- name: "Check local ansible version >= {{ minimal_ansible_version }}"
  delegate_to: localhost
  vars:
    ansible_connection: local
  run_once: true
  assert:
    msg: "Ansible must be {{ minimal_ansible_version }} or higher"
    that:
      - ansible_version.string is version(minimal_ansible_version, ">=")

- name: PREREQUIREMENTS | Get os-release
  raw: cat /etc/os-release
  register: os_release
  changed_when: false

- name: PREREQUIREMENTS | ArchLinux
  when: os_release.stdout.find("ID=arch") != -1
  block:
    - name: PREREQUIREMENTS | Update package index (pacman)
      raw: pacman -Sy
      changed_when: false
    - name: PREREQUIREMENTS | Install packages (pacman)
      raw: pacman --needed --noconfirm -S {{ archlinux_prerequirements_packages|join(" ") }}
      register: command_res
      changed_when: command_res.stdout.find('there is nothing to do') == -1

- name: PREREQUIREMENTS | Ubuntu
  when: os_release.stdout.find("ID=ubuntu")
  block:
    - name: PREREQUIREMENTS | Update package index (apt)
      raw: apt update
      changed_when: false
    - name: PREREQUIREMENTS | Install packages (apt)
      raw: apt install -y {{ ubuntu_prerequirements_packages|join(" ") }}
      register: command_res
      changed_when: command_res.stdout.find('0 upgraded, 0 newly installed, 0 to remove and ') == -1

- name: PREREQUIREMENTS | Gather facts
  setup: null

- name: PEREQUIREMENTS | Update inventory
  set_fact:
    ansible_python_interpreter: python3
