How to make Ansible use certain Python libs?

I have

`
$ which ansible
/usr/bin/ansible
user@hostname$ /usr/bin/ansible --version
ansible 2.4.0.0
config file = /users/user/.ansible.cfg
configured module search path = [u’/users/user/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /local/python/lib/python2.7/site-packages/ansible-2.4.0.0-py2.7.egg/ansible
executable location = /usr/bin/ansible
python version = 2.7.14 (default, Oct 10 2017, 13:19:29) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]

`

However, I want Ansible to use

$ which python2.7 /usr/local/bin/python2.7 user@hostname$ python2.7 -V Python 2.7.14

I have the following in my ansible.cfg file in my home dir

ansible_python_interpreter = /usr/local/bin/python2.7

What’s even more confusing is when I run ansible-galaxy to say create a role, it tries to use python2.6 libs, and I get…

`
$ ansible-galaxy init test-dict
Traceback (most recent call last):
File “/usr/bin/ansible-galaxy”, line 4, in
import(‘pkg_resources’).run_script(‘ansible==2.4.0’, ‘ansible-galaxy’)
File “/usr/lib/python2.6/site-packages/pkg_resources/init.py”, line 3037, in
@_call_aside
File “/usr/lib/python2.6/site-packages/pkg_resources/init.py”, line 3021, in _call_aside
f(*args, **kwargs)
File “/usr/lib/python2.6/site-packages/pkg_resources/init.py”, line 3050, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File “/usr/lib/python2.6/site-packages/pkg_resources/init.py”, line 655, in _build_master
ws.require(requires)
File “/usr/lib/python2.6/site-packages/pkg_resources/init.py”, line 969, in require
needed = self.resolve(parse_requirements(requirements))
File “/usr/lib/python2.6/site-packages/pkg_resources/init.py”, line 855, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The ‘cryptography’ distribution was not found and is required by ansible

`

How can I straighten all this out so Ansible uses the /usr/local/*/python2.7 paths?

You should look at the shebang in /usr/bin/ansible, I’m guessing it doesn’t point to /usr/local/bin/python2.7

ansible_python_interpreter only affects module execution, not the python interpreter the main ansible process uses.

Likely you should uninstall ansible, and install using that new python. Maybe something like /usr/local/bin/pip2.7 install ansible

That is just an assumption, you’ll need to fill in the blanks.

Thanks, that was the issue, the shebang was wrong. I just did a

$ pip install ansible

…which installed 2.4.2.0, and it works now.