Unable to use yum on target RHEL 8.6 host that has python3.12

I am trying to use ansible (core 2.17.7) to run a playbook on a target RHEL 8.6 host. I know RHEL 8.6 ships with python3.6, but I have already compiled and built python3.12 on the target host, as well as updated the symlinks

I can run python --version on the target host and it does return Python 3.12.8

However, when I try running my playbook (even when specifying the ‘ansible_python_interpreter: /usr/bin/python’ var in the playbook), it keeps returning with the same error.

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: SyntaxError: future feature annotations is not defined
fatal: [10.17.12.133]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 10.17.12.133 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"<stdin>\", line 12, in <module>\r\n  File \"<frozen importlib._bootstrap>\", line 971, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 951, in _find_and_load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 894, in _find_spec\r\n  File \"<frozen importlib._bootstrap_external>\", line 1157, in find_spec\r\n  File \"<frozen importlib._bootstrap_external>\", line 1131, in _get_spec\r\n  File \"<frozen importlib._bootstrap_external>\", line 1112, in _legacy_get_spec\r\n  File \"<frozen importlib._bootstrap>\", line 441, in spec_from_loader\r\n  File \"<frozen importlib._bootstrap_external>\", line 544, in spec_from_file_location\r\n  File \"/tmp/ansible_ansible.legacy.dnf_payload_xzwufs6b/ansible_ansible.legacy.dnf_payload.zip/ansible/module_utils/basic.py\", line 5\r\nSyntaxError: future feature annotations is not defined\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Any help would be appreciated!

Read Issue with Ansible on Rocky Linux 8.10 (Python 3.12) – "future feature annotations is not defined" - #2 by sivel

1 Like

Ansible has some python dependencies, including the future module. How did you install ansible on top of your python? using python 3.12’s pip command?

Unless you’re willing to track down every single papercut, such as you not having the deps for ansible, you’re better off installing Python 3.12 in The Recommended Way.

Controller and target do not require the same Python, Ansible itself supports different version ranges of Python for controller vs targets.

1 Like