I have some lookup plugins that import some custom python modules, and I’m gettting python errors during execution because it can’t find them. I need a way to set the PYTHONPATH environment variable prior to playbook execution, or somehow achieve the same result. Any ideas?
This is going to be super tricky because we also isolate the process using bubblewrap, so your chance of gaining access to another interpreter is pretty small unless you disable that. This is generally not something we’ve supported in any way in the past.
If you need to run some lookup plugins you can put them alongside your playbooks and install what dependencies you need in the /var/lib/awx/venv/awx virtualenv.
Hmm, that doesn’t really work in this case because we manage our custom python code in RPMs using yum, not pip, so it’s not possible to install them in the virtualenv.
I noticed under Settings → Jobs, there is a field named “EXTRA ENVIRONMENT VARIABLES” but it’s disabled because it says its managed in a config file somewhere. Would adding PYTHONPATH there help in this case?
maybe, you can find the settings files in the container. You are definitely on your own for that one though… I wouldn’t expect it to work very well at all
So … here’s what I’ve done:
- Modified installer/local_docker/tasks/main.yml to include an optional set of volumes.
- Created installer/group_vars/all to specify my custom settings.
I’m then taking advantage of site .pth files to point python at the right set of libs.
This should allow someone to install python packages on a host machine that can be used by the AWX container.
Custom vars:
$ cat installer/group_vars/all.yml
custom_ansible_dir: “/opt/ansible”
task_volumes:
“/opt/pypath.pth:/usr/lib/python2.7/site-packages/pypath.pth”
“/opt/custom_pylib:/opt/custom_pylib”
pth file:
$ cat /opt/pypath.pth
/opt/custom_pylib
Custom tasks: