---
# Some Fedora based distros ship without Python installed

- name: Check if bootstrap is needed
  raw: which python
  register: need_bootstrap
  failed_when: false
  changed_when: false
  tags:
    - facts

- name: Add proxy to dnf.conf if http_proxy is defined
  community.general.ini_file:
    path: "/etc/dnf/dnf.conf"
    section: main
    option: proxy
    value: "{{ http_proxy | default(omit) }}"
    state: "{{ http_proxy | default(False) | ternary('present', 'absent') }}"
    no_extra_spaces: true
    mode: "0644"
  become: true
  when: not skip_http_proxy_on_os_packages

# libselinux-python3 is required on SELinux enabled hosts
# See https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#managed-node-requirements
- name: Install ansible requirements
  raw: "dnf install --assumeyes python3 python3-dnf libselinux-python3"
  become: true
  when:
    - need_bootstrap.rc != 0

# iproute is required for networking related facts gathering
# See https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_vars_facts.html#package-requirements-for-fact-gathering
# Note: It is not recommended way, but since the tasks execution order, put it here is the simplest way so far. We can move it to a proper place later.
# TODO: move this to roles/kubernetes/preinstall/vars/main.yml -> pkgs variables
# Currently not possible because the collect the network facts before that step, needs reordering of the exec flow.
- name: Ensure iproute is installed
  package:
    name: iproute
    state: present
  become: true
