Issue with Ansible on Rocky Linux 8.10 (Python 3.12) – "future feature annotations is not defined"

Hi everyone,

I’m encountering an issue while running Ansible on Rocky Linux 8.10 (Green Obsidian) with Python 3.12 in localhost. I tested different versions of Ansible within a virtual environment, using the same playbook each time. Here are my findings:

  • Ansible 11.1.0 / Ansible-core 2.18:cross_mark: KO
  • Ansible 10.7 / Ansible-core 2.17.7:cross_mark: KO
  • Ansible 9.13.0 / Ansible-core 2.16.14:white_check_mark: OK

For both failing cases, I get the following error when running my playbook:

TASK [setup_server : Install required packages on CentOS] *************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: SyntaxError: future feature annotations is not defined
fatal: [localhost]: FAILED! => changed=false
  module_stderr: |-
    Traceback (most recent call last):
      File "<stdin>", line 12, in <module>
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 894, in _find_spec
      File "<frozen importlib._bootstrap_external>", line 1157, in find_spec
      File "<frozen importlib._bootstrap_external>", line 1131, in _get_spec
      File "<frozen importlib._bootstrap_external>", line 1112, in _legacy_get_spec
      File "<frozen importlib._bootstrap>", line 441, in spec_from_loader
      File "<frozen importlib._bootstrap_external>", line 544, in spec_from_file_location
      File "/tmp/ansible_ansible.legacy.dnf_payload_p6gl3c4k/ansible_ansible.legacy.dnf_payload.zip/ansible/module_utils/basic.py", line 5
    SyntaxError: future feature annotations is not defined
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

Steps to reproduce:

  1. Create a virtual environment with Python 3.12:
python3.12 -m venv ansible312venv
source ansible312venv/bin/activate
  1. Install different versions of Ansible:
pip install ansible==11.1.0  # Also tested with 10.7 and 9.7
  1. Run the playbook:
ansible-playbook playbook.yml --tags server -vvv

It seems like Ansible-core 2.17+ is not working properly with Python 3.12 on Rocky Linux 8.10.

Has anyone else encountered this issue? Is there a known workaround or fix?

Thanks in advance!

ansible-core 2.17 and newer do not support the default system python 3.6. I know you mention python3.12, however the dnf module requires the python dnf/rpm/gpgme/etc bindings, which are only packaged for the system python.

We have a feature called “respawn” which will attempt to respawn the module being executed, against known system python versions if the python bindings are missing from the python version specified by ansible_python_interpreter.

As such, in order for the dnf module to potentially work, it has to respawn on an interpreter that supports the python bindings it requires.

We’ve recently improved the method in which the other python interpreters are polled for respawn, to omit python versions that we no longer support. But that only cleans up the messaging on the failure to run the module.

So long story short, ansible-core 2.17+ simply cannot perform package related tasks against RHEL8. There are other modules in other collections that also won’t work as well due to this limitation.

So long story short, ansible-core 2.17+ simply cannot perform package related tasks against RHEL8.

I’m having trouble accepting this the end of the discussion given that RedHat owns Ansible. Is there any kind of roadmap or plan for resolving this?

RedHat has lifecycles for its software leaving supportability, Python 3.6’s end of life was in 2021. Not sure what kind of discussion remains to be had.

Ansible 2.16 and 2.17 go EOL this year. Is the official stance from RedHat to continue using the EOL Ansible 2.16 for the remaining life of RHEL 8?

Don’t know if I’ve ever seen an official RedHat person ever post here, even the open source project maintainers have been scarce since last summer. Might be more productive to open a ticket with RH and get their stance that way

You may want to check this response for more detailed information:

However, the long story short is the response I provided above, with the exception that Red Hat customers get extended critical security support for ansible-core 2.14 and ansible-core 2.16.

I ran into the same wall and built a solution hopefully worth sharing here.

The issue is a genuine incompatibility with no clean official fix: ansible-core >= 2.17 needs Python 3.10+ on the managed host, but python3-dnf on EL8 tops out at Python 3.9. The respawn mechanism that’s supposed to handle this fails because the respawned interpreter (3.6) doesn’t satisfy ansible-core 2.17’s own from __future__ import annotations requirement.

I built carlijoy.compat — a collection that backports the original ansible.builtin.dnf from ansible-core 2.15 as a self-contained executable that runs under /usr/libexec/platform-python (the EL8 system Python with dnf bindings). The module interface is identical to ansible.builtin.dnf.

pip install ansible-el-compat
# or
ansible-galaxy collection install carlijoy.compat
# Before
- ansible.builtin.dnf:
    name: httpd
    state: present

# After
- carlijoy.compat.dnf:
    name: httpd
    state: present

Repo: GitHub - CarliJoy/ansible-el-compat: EL8-compatible Ansible modules for ansible-core >= 2.17 · GitHub

ansible-core 2.21’s dnf module should also work with Rocky Linux and RHEL 8: Support core packaging operations against older python versions by sivel · Pull Request #86432 · ansible/ansible · GitHub

That’s awesome. Thanks for the reference.
Maybe someone could update: Incompatibility of ansible.builtin.dnf Module with Newer Python Versions Due to python3-dnf Dependency in Ansible Automation Platform. - Red Hat Customer Portal ?