---
- name: Prepare
  hosts: all

  pre_tasks:
    - name: "Installing packages on CentOS"
      ansible.builtin.yum:
        name:
          - net-tools
          - which
          - sudo
        state: present
      register: installation_dependencies
      until: installation_dependencies is succeeded
      when:
        - ansible_os_family == 'RedHat'

    - name: "Make sure the docs can be installed. (Debian)"
      ansible.builtin.lineinfile:
        path: /etc/dpkg/dpkg.cfg.d/excludes
        state: absent
        regexp: "path-exclude=/usr/share/doc/*"
      when:
        - ansible_os_family == 'Debian'

    # https://github.com/geerlingguy/ansible-role-java/issues/64
    - name: "Apt update"
      ansible.builtin.shell: "apt-get update && mkdir -p /usr/share/man/man1"
      register: installation_dependencies
      until: installation_dependencies is succeeded
      when:
        - ansible_os_family == 'Debian'

    - name: "Installing packages on NON-CentOS"
      ansible.builtin.apt:
        name:
          - net-tools
          - apt-utils
          - procps
          - python3-pip
          - gpg-agent
          - python3-apt
          - sudo
          - software-properties-common
        update_cache: true
        state: present
      register: installation_dependencies
      until: installation_dependencies is succeeded
      when:
        - ansible_os_family == 'Debian'

    - name: "Installing packages on Suse"
      community.general.zypper:
        name:
          - iproute2
          - which
        state: present
      register: installation_dependencies
      until: installation_dependencies is succeeded
      when:
        - ansible_os_family == 'Suse'
