---
- name: install podman
  package:
    name: podman
    state: latest
  when:
    - inventory_hostname in groups['crio']
    - ansible_distribution == "CentOS" or ansible_distribution == "RedHat" or ansible_distribution == "Rocky"

- name: install podman
  shell: |
    /etc/os-release
    echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_{{ ansible_distribution_version }}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
    curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_{{ ansible_distribution_version }}/Release.key" | sudo apt-key add -
    apt -y update
    apt -y upgrade
    apt install -y podman
  when:
    - inventory_hostname in groups['crio']
    - ansible_distribution == "Ubuntu"

- name: nerdctl tar.gz copy
  copy:
    src: "{{ role_path }}/files/host-agent/nerdctl-0.19.0-linux-amd64.tar.gz"
    dest: /root
  when:
    - inventory_hostname in groups['containerd']

- name: nerdctl unarchive
  unarchive:
    src: /root/nerdctl-0.19.0-linux-amd64.tar.gz
    dest: /usr/local/bin
    remote_src: yes
  when:
    - inventory_hostname in groups['containerd']

- name: host-agent.tar.gz copy
  copy:
    src: "{{ role_path }}/files/host-agent/host-agent.tar.gz"
    dest: /root/
  when:
    - inventory_hostname in groups['containerd'] or inventory_hostname in groups['docker'] or inventory_hostname in groups['crio']

- name: create host-agent directory
  file:
    path: /root/host-agent
    state: directory
  when:
    - inventory_hostname in groups['containerd'] or inventory_hostname in groups['docker'] or inventory_hostname in groups['crio']

- name: host-agent.tar.gz unarchive
  unarchive:
    src: /root/host-agent.tar.gz
    dest: /root/host-agent/
    remote_src: yes
  when:
    - inventory_hostname in groups['containerd'] or inventory_hostname in groups['docker'] or inventory_hostname in groups['crio']
