---
- name: Set up Kubernetes repository
  yum_repository:
    name: kubernetes
    description: Kubernetes
    baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
    enabled: yes
    gpgcheck: yes
    # Got "repomd.xml signature could not be verified for kubernetes" on zuul
    repo_gpgcheck: no
    gpgkey:
      - https://packages.cloud.google.com/yum/doc/yum-key.gpg
      - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

- name: Install kube CLIs
  package:
    name: "{{ item }}"
    state: present
    update_cache: yes
  with_items:
    - kubelet-{{ k8s_version }}
    - kubectl-{{ k8s_version }}
    - kubeadm-{{ k8s_version }}

# On CentOS 7, the kubeadm package adds a configuration file that overrides
# kubelet's cgroup driver to systemd, we want to use the default driver
# cgroupfs to get the same cgroup paths for resource limiting.
#
#   $ rpm -qf /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
#   kubeadm-1.9.3-0.x86_64
#
- name: Change kubelet cgroup driver
  replace:
    path: /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
    regexp: '(KUBELET_CGROUP_ARGS=)[^"]+'
    replace: '\1'
