---
- name: "Add gpg key (Ubuntu)"
  apt_key:
    url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
    state: present
  when: ansible_distribution == "Ubuntu"

- name: "Add kubernetes source list (Ubuntu)"
  apt_repository:
    repo: "deb http://apt.kubernetes.io/ kubernetes-{{ ansible_distribution_release }} main"
    state: present
    filename: "kubernetes"
  when: ansible_distribution == "Ubuntu"

- name: "Update the repository cache (Ubuntu)"
  apt:
    update_cache: yes
  when: ansible_distribution == "Ubuntu"

- name: "Add Kubernetes repository and install gpg key (CentOS)"
  yum_repository:
    name: kubernetes
    description: Kubernetes repository
    baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
    gpgcheck: yes
    enabled: yes
    repo_gpgcheck: yes
    gpgkey:
      - https://packages.cloud.google.com/yum/doc/yum-key.gpg
      - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
  when: ansible_distribution == "CentOS"

- name: "Disable SELinux (CentOS)"
  selinux:
    state: disabled
  when: ansible_distribution == "CentOS"

- name: "Install kubelet,kubeadm,kubectl (CentOS)"
  yum: state=present name={{ item }}
  with_items:
    - kubelet
    - kubeadm
    - kubectl
  when: ansible_distribution == "CentOS"

- name: "Install kubelet, kubeadm, kubectl (Ubuntu)"
  apt: name={{item}} state=installed
  with_items:
    - kubelet
    - kubeadm
    - kubectl
  when: ansible_distribution == "Ubuntu"
