How to make Ansible use certain Python libs?

33 views
Skip to first unread message

ZillaYT

unread,
Jan 29, 2018, 3:41:32 PM1/29/18
to Ansible Project
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 <module>
    __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 <module>
   
@_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?

Matt Martz

unread,
Jan 29, 2018, 3:47:11 PM1/29/18
to ansible...@googlegroups.com
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/adfce955-abda-4f37-b6a7-74cfa6e8a8fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

ZillaYT

unread,
Jan 29, 2018, 4:12:22 PM1/29/18
to Ansible Project
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.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages