How to make ansible use a certain Python path/executable?

24,551 views
Skip to first unread message

ZillaYT

unread,
Oct 31, 2017, 3:12:56 PM10/31/17
to Ansible Project
How do I force Ansible to use a certain version of Python? Is it in the ansible.cfg file? For example, I see via "ansible --version" command that it's using /usr/local/bin/python v2.6.6, but I want it to use /local/python/bin/python v2.7.x for example?

Matt Martz

unread,
Oct 31, 2017, 3:20:04 PM10/31/17
to ansible...@googlegroups.com

On Tue, Oct 31, 2017 at 2:12 PM, ZillaYT <zil...@gmail.com> wrote:
How do I force Ansible to use a certain version of Python? Is it in the ansible.cfg file? For example, I see via "ansible --version" command that it's using /usr/local/bin/python v2.6.6, but I want it to use /local/python/bin/python v2.7.x for example?

--
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/a2fb46cb-149c-41ca-838f-a28e78d5c423%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

ZillaYT

unread,
Oct 31, 2017, 3:58:49 PM10/31/17
to Ansible Project
Thanks again!


On Tuesday, October 31, 2017 at 3:20:04 PM UTC-4, Matt Martz wrote:
On Tue, Oct 31, 2017 at 2:12 PM, ZillaYT <zil...@gmail.com> wrote:
How do I force Ansible to use a certain version of Python? Is it in the ansible.cfg file? For example, I see via "ansible --version" command that it's using /usr/local/bin/python v2.6.6, but I want it to use /local/python/bin/python v2.7.x for example?

--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

ZillaYT

unread,
Nov 1, 2017, 11:00:13 AM11/1/17
to Ansible Project
I set ansible_python_interpreter in my ansible.cfg and then in my playbook to point to a Python3.5 installation, but when I still get

$ ansible --version
ansible 2.4.0.0
  config file = /users/myuser/.ansible.cfg
  configured module search path = [u'/users/myuser/.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 = /local/python/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)]




On Tuesday, October 31, 2017 at 3:20:04 PM UTC-4, Matt Martz wrote:
On Tue, Oct 31, 2017 at 2:12 PM, ZillaYT <zil...@gmail.com> wrote:
How do I force Ansible to use a certain version of Python? Is it in the ansible.cfg file? For example, I see via "ansible --version" command that it's using /usr/local/bin/python v2.6.6, but I want it to use /local/python/bin/python v2.7.x for example?

--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Toshio Kuratomi

unread,
Nov 1, 2017, 11:27:55 AM11/1/17
to ansible...@googlegroups.com
It depends on whether you are trying to get ansible to use a different python interpreter for the modules it runs or /usr/bin/ansible on the controller.  Matt Martz's info oncansible_python_interpreter is correct for the module side.  For the controller side, you would need to change the shebang line of the ansible script.  If you are installing ansible you can do that by using something like this to install: /local/python/bin/python setup.py install

When I test and have to use many different python interpreters to test with I often don't install and instead invoke ansible like this:

/usr/bin/python3.5 $(which ansible) --version

What works best for you will depend on your use case.

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/d18d5856-0ef7-405e-b927-1f82d5d5fa74%40googlegroups.com.

ZillaYT

unread,
Nov 1, 2017, 11:54:42 AM11/1/17
to Ansible Project
Got it, thanks.
Reply all
Reply to author
Forward
0 new messages