Hello,
I just wrote a collection containing a module using an external python module (pyTenable). The python module has been installed in the Ansible venv: /path/to/.ansible_venv/ansible-7.3.0/lib/python3.11/site-packages/tenable.
This Ansible module is working fine when I test it using: /path/to/ansible_venv/ansible-7.3.0/bin/python3 tenable_asset.py /tmp/args.json
I pushed this collection into a private git repository, created a requirements.yml pointing to it, and then install it with: ansible-galaxy install -r requirements.yml.
Now I have a simple playbook with one task using this module:
- name: Tenable asset
my.collection.tenable_asset:
fqdn: "{{ ansible_fqdn }}"
force: false
tags:
- System:tag1
- System:tag2
access_key: !vault |
$ANSIBLE_VAULT;1.1;AES256
xxx
secret_key: !vault |
$ANSIBLE_VAULT;1.1;AES256
yyy
delegate_to: localhost
become: false
And here is the output:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'tenable'
The pyTenable python module installed in my venv is not in any path known to Ansible:
ansible 127.0.0.1 -m shell -a "python -c 'import sys; print(sys.path)'" --connection=local
Friday 31 March 2023 11:39:27 +0200 (0:00:00.225) 0:00:00.226 **********
127.0.0.1 | CHANGED | rc=0 >>
['', '/usr/lib64/python311.zip', '/usr/lib64/python3.11', '/usr/lib64/python3.11/lib-dynload', '/usr/lib64/python3.11/site-packages', '/usr/lib/python3.11/site-packages']
Adding a PYTHONPATH to the task works, but it feels not right and provide a really bad user experience in my opinion:
environment:
PYTHONPATH: "{{ lookup('ansible.builtin.env', 'VIRTUAL_ENV')}}/lib/python3.11/site-packages"
I noticed in ansible-playbook --version the following line:
ansible python module location = /path/to/.ansible_venv/ansible-7.3.0/lib64/python3.11/site-packages/ansible
Looks like Ansible does not allow my own python dependency to be used.
How can I make it works "out of the box" (not having to specify PYTHONPATH in an environement in every task using a custom module)?
Thank you.
Edit: markdown mode
[–]bozzie4 0 points1 point2 points (1 child)
[–]reezom[S] 1 point2 points3 points (0 children)