---
- name: Add docker script
  command: curl -fsSL https://get.docker.com -o /root/get-docker.sh

- name: install docker
  command: sh /root/get-docker.sh

- name: Create docker configuration directory
  file:
    path: /etc/docker
    state: directory

- name: Configure docker
  template:
    src: daemon.json.j2
    dest: /etc/docker/daemon.json
  notify:
    - Reload systemd configuration
    - Restart docker service

- name: Install kubernetes
  block:
    - name: 'Add kubernetes repo key'
      apt_key:
        url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
        state: present
      become: true
    - name: Add kubernetes repository
      apt_repository:
        repo: deb http://apt.kubernetes.io kubernetes-xenial main
        state: present
        filename: 'kubernetes'
      become: true
    - name: Install kubernetes components
      apt: 
        name: ['kubelet={{kubernetes_version}}-*', 'kubeadm={{kubernetes_version}}-*', 'kubectl={{kubernetes_version}}-*']
        state: present
        update_cache: yes
        force: yes
        dpkg_options: force-downgrade

- name: Hold kubernetes packages
  dpkg_selections:
    name: "{{item}}"
    selection: hold
  with_items:
    - kubelet
    - kubectl
    - kubeadm

