# AlmaLinux and “python3-dnf”

**URL:** <https://forum.ansible.com/t/almalinux-and-python3-dnf/44262>\
**Category:** Get Help\
**Tags:** almalinux, ansible, ubuntu\
**Created:** [August 8, 2025, 4:33pm UTC](https://forum.ansible.com/t/almalinux-and-python3-dnf/44262 "2025-08-08T16:33:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric-cap](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/eric-cap/32/9244_2.png) [@Eric-cap](https://forum.ansible.com/u/Eric-cap)\
**Post date:** [August 8, 2025, 4:33pm UTC](https://forum.ansible.com/t/almalinux-and-python3-dnf/44262/1 "2025-08-08T16:33:23Z")

</div>

Hello All,

I’m facing an issue with Ansible and Almalinux target host.

My Ansible is hosted on Ubuntu, I can deploy on Debian and Suze without any pb.

I added a new OS on my configuration, Almalinux 8

When I tried to launch my script the following error appears :

FAILED! =\> {“changed”: false, “msg”: “Could not import the dnf python module using /usr/bin/python3.11 (3.11.13 (main, Jul 1 2025, 10:23:30) [GCC 8.5.0 20210514 (Red Hat 8.5.0-26)]). Please install `python3-dnf` package or ensure you have specified the correct ansible\_python\_interpreter. (attempted [‘/usr/libexec/platform-python’, ‘/usr/bin/python3’, ‘/usr/bin/python’])”, “results”: }

Maybe I didn’t check properly but I don’t found any solution, I tried to set ansible\_python\_interpreter: /usr/bin/python3 same way

I think there are a trick to manage installation/configuration on ansible target ?

Thank you for your support,

Eric.

---

<div class="post-metadata">

**Author:** ![mkrizek](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mkrizek/32/2055_2.png) [@mkrizek](https://forum.ansible.com/u/mkrizek)\
**Post date:** [August 8, 2025, 5:01pm UTC](https://forum.ansible.com/t/almalinux-and-python3-dnf/44262/2 "2025-08-08T17:01:33Z")

</div>

In order to run the `dnf` module you need to use the system Python for which the Python dnf bindings (`python3-dnf`) are available. I believe that for AlmaLinux 8 the system Python version is 3.6 which also means that you need to run the version of `ansible-core` that supports running Python 3.6 on target machines, the last such version is `ansible-core` `2.16`, see [Releases and maintenance — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix).

---

<div class="post-metadata">

**Author:** ![Eric-cap](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/eric-cap/32/9244_2.png) [@Eric-cap](https://forum.ansible.com/u/Eric-cap)\
**Post date:** [August 12, 2025, 1:07pm UTC](https://forum.ansible.com/t/almalinux-and-python3-dnf/44262/3 "2025-08-12T13:07:37Z")

</div>

First thank you for your reply,

My ansible-core is 2.18.7 but more invest reveal that the OS were update form CentOS7 to Almalinux8, and the issue could be related to “alternatives” configuration. I’m not confident with the “alternatives” configuration

If I launch my script on a fresh installed workstation on Alamlinux8 the installation pass

That’s sound really strange for me, the OS upgrade could affect the system ?

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [August 14, 2025, 2:09pm UTC](https://forum.ansible.com/t/almalinux-and-python3-dnf/44262/4 "2025-08-14T14:09:50Z")

</div>

Martin is correct, you cannot use `ansible-core>=2.17` with the yum/dnf modules on EL8 and older OS systems (RHEL/CentOS/Alma/Rocky, etc). The OS upgrade and alternatives configuration have nothing to do with it, and in fact shouldn’t have worked before the CentOS7 → AlmaLinux8 upgrade either.

@sivel has covered this topic extensively. He has a short but detailed explanation here: [Issue with Ansible on Rocky Linux 8.10 (Python 3.12) – "future feature annotations is not defined" - #2 by sivel](https://forum.ansible.com/t/issue-with-ansible-on-rocky-linux-8-10-python-3-12-future-feature-annotations-is-not-defined/41117/2) and a longer and more thorough explanation here: [Python 3.7+ Impact on EL8 (future for EL9) - #13 by sivel](https://forum.ansible.com/t/python-3-7-impact-on-el8-future-for-el9/6229/13)

---

<div class="post-metadata">

**Author:** ![Eric-cap](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/eric-cap/32/9244_2.png) [@Eric-cap](https://forum.ansible.com/u/Eric-cap)\
**Post date:** [August 14, 2025, 3:26pm UTC](https://forum.ansible.com/t/almalinux-and-python3-dnf/44262/5 "2025-08-14T15:26:51Z")

</div>

Hello, yes you’re true ! But I cannot downgrade my Ansible. I found an alternative I’m using :

- name: LOGROTATE, logrotate installation  
ansible.builtin.command: dnf install -y logrotate  
become: True

instead of

- name: Logrotate, logrotate installation  
dnf:  
name: logrotate

I hope I’m on a good way, thank to all people who reply to me !

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [August 14, 2025, 3:58pm UTC](https://forum.ansible.com/t/almalinux-and-python3-dnf/44262/6 "2025-08-14T15:58:46Z")

</div>

Yep, you can use `command` or `shell` instead if you must use newer Ansible.

However, you _can_ use different versions of Ansible side-by-side using venv. Pipx and Pipenv are both good for this. Or you can use `ansible-navigator` and use EE’s with specific Ansible versions. If you use AWX/AAP, you can also specify the EE’s to use there as well.

Just want to make sure you know that you have options.

---

<div class="post-metadata">

**Author:** ![Eric-cap](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/eric-cap/32/9244_2.png) [@Eric-cap](https://forum.ansible.com/u/Eric-cap)\
**Post date:** [August 18, 2025, 7:19am UTC](https://forum.ansible.com/t/almalinux-and-python3-dnf/44262/7 "2025-08-18T07:19:28Z")

</div>

I didn’t know that I also have this option, I’ll learn on this topic too.  
Thank you for your help !

---

<div class="post-metadata">

**Author:** ![Kound](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kound/32/10738_2.png) [@Kound](https://forum.ansible.com/u/Kound)\
**Post date:** [May 16, 2026, 7:06am UTC](https://forum.ansible.com/t/almalinux-and-python3-dnf/44262/8 "2026-05-16T07:06:13Z")

</div>

Hey, I ran into this exact problem and ended up building a proper fix rather than a workaround.

The root cause: ansible-core \>= 2.17 requires Python 3.10+ on managed hosts (modules use `from __future__ import annotations`), but `python3-dnf` on EL8 only exists for Python 3.6/3.9. So there’s no supported Python version that satisfies both constraints at once.

I built `carlijoy.compat` — an Ansible collection that backports the original `ansible.builtin.dnf` from ansible-core 2.15 as a self-executing zip that runs under `/usr/libexec/platform-python` (the EL8 system Python that has `python3-dnf`). It’s a proper drop-in with full feature parity, not a subprocess reimplementation.

This works as ansible-modules can be all programm that accepts a JSON as stdin and returns a JSON. In this case ansible treats the backport as a standalone program (which it kind of is).

Install via pip/uv (no ansible-galaxy needed):

```bash
pip install ansible-el-compat

```

Or via Galaxy:

```bash
ansible-galaxy collection install carlijoy.compat

```

Then replace `ansible.builtin.dnf` with `carlijoy.compat.dnf` in your playbooks — the interface is identical.

Source and details: [GitHub - CarliJoy/ansible-el-compat: EL8-compatible Ansible modules for ansible-core \>= 2.17 · GitHub](https://github.com/CarliJoy/ansible-el-compat)

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [May 16, 2026, 7:07am UTC](https://forum.ansible.com/t/almalinux-and-python3-dnf/44262/9 "2026-05-16T07:07:09Z")

</div>

ansible-core 2.21’s `dnf` module should also work with AlmaLinux 8 (and Rocky Linux 8 and RHEL 8): [Support core packaging operations against older python versions by sivel · Pull Request #86432 · ansible/ansible · GitHub](https://github.com/ansible/ansible/pull/86432)
