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.

1 Like