Should pip still use /usr/bin/python if the ansible_python_interpreter env var is set to a virtualenv

256 views
Skip to first unread message

Wajdi Al-Hawari

unread,
Jan 23, 2018, 7:59:58 AM1/23/18
to Ansible Project
The Scenario: 

I have encountered an issue that I first drafted as a bug, but before I post it, I wanted to ask about it here first.

The scenario I'm facing is wanting to run my playbook without explicitly setting a virtualenv in my pip module. So, instead I'm using the ansible_python_interpreter to point to the python interpreter I want to use. 

example call: ansible-playbook -i inventory --connection=local playbook.yml -e ansible_python_interpreter=/home/user/foo_proj/venv

I noticed that when running my playbook with my python interpreter set to /home/user/foo_proj/venv/, my expectation was for the venv to be within that context using /home/user/foo_proj/venv/bin/pip. It, however instead was using /usr/local/bin/pip3 per the small snippet of my output: 

ok: [localhost] => {
"changed": false,
"cmd": "/usr/local/bin/pip3 install docker-compose",
"invocation": {
"module_args": {

I do have a growing suspicion that the intention of this "ansible_python_interpreter" environment variable is not necessarily meant for virtual environments (meaning my supposed bug is invalid) but specific locations of the Python executable you want to use, thus, in turn using its respecting /usr/bin/pipX (X being the version). 

It is fairly clear even from the code here that the behaviour is to look for /usr/bin/pip. 

The question:

So, my question is whether using the ansible_python_interpreter should in fact get the pip module to use the respective environment pip, or is it as specified in the code not intended to change the pip module path to the virtualenv pip, but rather to the system level pip for the version of Python being specified by ansible_python_interpreter? 

Wajdi Al-Hawari

unread,
Jan 23, 2018, 8:01:51 AM1/23/18
to Ansible Project
I forgot to specify my Ansible version. I am using: 2.4.2.0
Reply all
Reply to author
Forward
0 new messages