---
- name: Add crio yum repository
  command: sudo curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable.repo https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/CentOS_7/devel:kubic:libcontainers:stable.repo

- name: Add crio yum repository
  command: sudo curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable:cri-o:1.23.repo https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:1.23/CentOS_7/devel:kubic:libcontainers:stable:cri-o:1.23.repo

- name: Create crio configuration directory
  file:
    path: /etc/containers/registries.conf.d
    state: directory

- name: Configure crio
  template:
    src: myregistry.conf.j2
    dest: /etc/containers/registries.conf.d/myregistry.conf
  notify:
    - Restart crio service

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

- meta: flush_handlers

- name: Enable crio service
  service:
    name: crio
    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
  notify:
    - Reload systemd configuration

- name: Manual Daemon Reload
  command: systemctl daemon-reload  
