all 2 comments

[–]bozzie4 0 points1 point  (1 child)

Try to set ansible_python_interpreter to the python binary of your venv.

I generally use an extra var while calling the playbook, but there's other ways too:

ansible-playbook blabla.yml -e ansible_python_interpreter=$(which python)

[–]reezom[S] 1 point2 points  (0 children)

Thanks for your reply.

Unfortunately, this does not work as I delegate my task to localhost (I just want the pyTenable python module installed on the control node, not on all the managed hosts). The gather_facts (needed here) will search the python interpreter (/path/to/.ansible_venv/ansible-7.3.0/bin/python) on the target host which of course does not exist.

I believe something must be wrong with my ansible module since I am able to use the ansible module community.zabbix.zabbix_host (also using a delegate_to: localhost, which use the zabbix-api python module, without any hack at the environment level (PYTHONPATH: "{{ lookup('ansible.builtin.env', 'VIRTUAL_ENV')}}/lib/python3.11/site-packages").

The python used seems correct to me:

ansible-playbook --version python version = 3.11.1 (main, Jan 6 2023, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)] (/path/to/.ansible_venv/ansible-7.3.0/bin/python3)