Ensure python3-dnf is installed on Fedora 41+ hosts

dnf5 requires neither python3-rpm nor python3-dnf, so we cannot
assume they are installed (as they always were before). ansible's
package_facts needs python3-rpm (even in the latest upstream
version), so we at least need that. The ansible in rhel9 (which
is what's on batcave01 currently) does not support dnf5 at all,
so we need python3-dnf installed so it can use its dnf3/4
support. python3-dnf relies on python3-rpm, so we can just
check for and install python3-dnf. Once batcave01 is updated to
an ansible that supports dnf5 we won't need python3-dnf, but we
*will* still need python3-rpm.

Stuffing this in yumrepos.yml as it runs on everything, early,
and is packaging-related. We could make it a separate task but
then we'd need to make every playbook include it...

Signed-off-by: Adam Williamson <awilliam@redhat.com>
This commit is contained in:
Adam Williamson 2024-11-22 11:06:09 -08:00
parent db0e3dc08b
commit 73db9ea127

View file

@ -148,3 +148,19 @@
- config
- packages
- yumrepos
# when batcave01 is on a newer ansible we won't need python3-dnf but
# we *will* need python3-rpm (package_facts fails without it)
- name: Ensure that python3-dnf is installed (needed till ansible on batcave01 supports dnf5)
when: "ansible_distribution == 'Fedora' and ansible_distribution_major_version|int > 40 and ansible_cmdline.ostree is not defined"
block:
- name: Check whether python3-dnf is installed
ansible.builtin.command: "rpm -q python3-dnf"
register: p3dnf
failed_when: "1 != 1"
changed_when: "1 != 1"
check_mode: no
- name: Install python3-dnf with direct dnf command
ansible.builtin.command: "dnf -y install python3-dnf"
when: "p3dnf.rc != 0"