SvennD
Fix Ansible dnf/yum on RHEL8
May 12, 2025

Fix Ansible dnf/yum on RHEL8

Posted on May 12, 2025  •  1 minutes  • 151 words

Ansible (-core) 2.17 and above requires a system Python version that supports future and respawn [1, 2]. However, the default Python 3.6 does not. Installing a newer Python version like 3.12 is possible, but it lacks the python3.12-dnf package. As a result, you can’t use dnf, package, or yum modules with newer Ansible versions on RHEL 8.

While RHEL 8 is EOL, many RHEL 8-based distributions (Alma, Rocky, etc.) are still maintained. Here’s my workaround:

# setup a virtual env
python3 -m venv legacy_ansible

# load the virtual env
source legacy_ansible/bin/activate

# install the last working ansible-core !
pip3 install ansible-core==2.16.14

# if you have ansible systemwide installed run the local version
./legacy_ansible/bin/ansible -- version
ansible [core 2.16.14]

In the playbook I define the interpreter, so it does take the system python interpreter with dnf module and not the newer one.

  vars:
    ansible_python_interpreter: /bin/python3

Patched for now :)

img by chatGPT

Support

If you enjoyed this website, consider buying me a Dr. Pepper

Buy me a Dr PepperBuy me a Dr Pepper