---
- name: Add containerd yum repository
  command: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

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

- name: Configure containerd
  template:
    src: config.toml.j2
    dest: /etc/containerd/config.toml
  notify:
    - Restart containerd service

- name: Install required packages
  yum:
    name: ['containerd']
    state: present
  notify:
    - Reload systemd configuration
    - Restart containerd service

- meta: flush_handlers

- name: Enable containerd service
  service:
    name: containerd
    enabled: True
    state: started
   
- name: Add kubernetes yum repository
  ansible.builtin.yum_repository:
    name: kubernetes
    description: kubernetes
    baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
    enabled: 1
    gpgcheck: 1
    gpgkey: https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

- name: Install kubernetes utils
  ansible.builtin.yum:
    name: ['kubelet-{{kubernetes_version}}','kubeadm-{{kubernetes_version}}','kubectl-{{kubernetes_version}}']
    exclude: kubernetes