---
# 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
  environment: {}
  tags:
    - facts

- name: Check if a proxy is set in /etc/dnf/dnf.conf
  raw: grep -qs 'proxy=' /etc/dnf/dnf.conf
  register: need_http_proxy
  failed_when: false
  changed_when: false
  # This command should always run, even in check mode
  check_mode: false
  environment: {}
  when:
    - http_proxy is defined

- name: Add http_proxy to /etc/dnf/dnf.conf if http_proxy is defined
  raw: echo 'proxy={{ http_proxy }}' >> /etc/dnf/dnf.conf
  become: true
  environment: {}
  when:
    - http_proxy is defined
    - need_http_proxy.rc != 0

- name: Install python3 on fedora
  raw: "dnf install --assumeyes --quiet python3"
  become: true
  environment: {}
  when:
    - need_bootstrap.rc != 0

# 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 libselinux-python3
  package:
    name: libselinux-python3
    state: present
  become: true