ansible / awx-ee

An Ansible execution environment for AWX project
https://quay.io/ansible/awx-ee
Other
132 stars 158 forks source link

Problems related to old Python version? #133

Closed hanikat closed 1 year ago

hanikat commented 1 year ago

Hi,

I'm having some problems running my own modules in EEs. One of the modules I'm having problem with is using the Python module 'exchangelib' which requires Python 3.8. To be able to use this module in our EE we compile our own EE with the following row within our Python-dependency file: exchangelib>=4.7.6

This seems to work fine and I have confirmed that the module is indeed installed within our EE at /usr/local/lib/python3.8/site-packages/exchangelib. However, when I try to run a playbook within our EE using this module I get the following error message: "module_stderr": "Traceback (most recent call last):\n File \"/root/.ansible/tmp/ansible-tmp-1662284848.2828457-67-168865680504031/AnsiballZ_read_mail.py\", line 107, in <module>\n _ansiballz_main()\n File \"/root/.ansible/tmp/ansible-tmp-1662284848.2828457-67-168865680504031/AnsiballZ_read_mail.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/root/.ansible/tmp/ansible-tmp-1662284848.2828457-67-168865680504031/AnsiballZ_read_mail.py\", line 48, in invoke_module\n run_name='__main__', alter_sys=True)\n File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n mod_name, mod_spec, pkg_name, script_name)\n File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_epm.exchange_online.read_mail_payload_shislbyu/ansible_epm.exchange_online.read_mail_payload.zip/ansible_collections/epm/exchange_online/plugins/modules/read_mail.py\", line 68, in <module>\nModuleNotFoundError: No module named 'exchangelib'\n"

So it seems like the exhcnagelib Python module can't be found, even though I know it is installed. What I noticed in the above error message was that the path /usr/lib64/python3.6 was referenced, even though our module requires Python 3.8. So I ran a playbook within our EE to retrieve the content of ansible_facts and I noticed that the Ansible version section of the output said: "python_version": "3.6.8". Thus, the Python version used in the EE indeed seems to be 3.6. So I'm guessing the usage of this older version of Python is what's causing my problems.

I have confirmed that Python 3.8 is installed in our EE, but I can't seem to figure out how to change the version which Ansible uses when executing playbooks within the EE. I have tried adding a ansible.cfg file and specifying the interpreter_python variable and attempting to uninstall Python3.6 during EE compilation, but it does not seem to help.

Other info: To develop our playbooks we use a development server where we compile our EEs and run them in docker with the following command: ansible-runner run --process-isolation --process-isolation-executable docker --container-image awx-exec-env -p playbooks/Test.yml /development/anisble-runner/ --container-volume-mount "/development/Ansible/:/runner/project" --container-volume-mount "/development/ansible-runner/inventory/:/runner/inventory/" -v I have tried running the same module locally on our development server with Ansible version 2.10.8 anv Python version 3.10.4 installed and the moudle runs without any problem.

TL;DR So my question is: what steps are required to change the Python version which Ansible uses within the EE?

fosterseth commented 1 year ago

You may need to set the ansible_python_interpreter variable to point to your python 3.8 executable

see this documentation on how to do that https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html

you can specify it as a host variable, or put it in ansible.cfg

hanikat commented 1 year ago

You may need to set the ansible_python_interpreter variable to point to your python 3.8 executable

see this documentation on how to do that https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html

you can specify it as a host variable, or put it in ansible.cfg

Thanks for your reply.

I tried this approach, but I did not manage to get it to work within my EE. However, I found this other issue #119 where he changed the path which /usr/libexec/platform-python is pointing to. I managed to solve my problems by using the same approach and adding the following row to my "additional_build_steps" section of the EE specification file: RUN ln -sf /usr/bin/python3.8 /usr/libexec/platform-python

I was a bit afraid that it would cause problems for our other playbooks and modules which does not need Python 3.8+, but so far it seems to be working fine. Therefor, I will close this issue since this simple steps seems to have resolved my problem.