I'm executing:
ansible-playbook --version
And I get the following output:
ansible-playbook 2.5.14
config file = /etc/ansible/ansible.cfg
configured module search path = [u'~/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]
But when I execute:
ansible-playbook --version -e 'ansible_python_interpreter=/usr/bin/python3'
I'm having exactly the same output. I was expecting having something like:
python version = 3.5.2
What am I misunderstanding?
To change the python interpreter used on a managed host you can either use an extra or inventory variable, as per your question. This does not change the version of python used to execute ansible locally - which is mentioned in the other answer.
To confirm that you are using a different interpreter on the managed host, you will need more verbose output (at least 3 'v's, -vvv
). Running python --version
in a shell command is just going to show you what the system's default python version is.
Example
Python2 interpreter:
$ ansible localhost -a 'python --version' -e 'ansible_python_interpreter=/usr/bin/python2' -vvv
ansible 2.8.1
<snip>
python version = 3.7.3 (default, May 11 2019, 00:38:04) [GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]
<snip>
'/bin/sh -c '"'"'/usr/bin/python2 /home/mattp/.ansible/tmp/ansible-tmp-1564023345.0848873-106174541151316/AnsiballZ_command.py && sleep 0'"'"''
<snip>
localhost | CHANGED | rc=0 >>
Python 2.7.16
Python3 interpreter:
$ ansible localhost -a 'python --version' -e 'ansible_python_interpreter=/usr/bin/python3' -vvv
ansible 2.8.1
<snip>
python version = 3.7.3 (default, May 11 2019, 00:38:04) [GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]
<snip>
'/bin/sh -c '"'"'/usr/bin/python3 /home/mattp/.ansible/tmp/ansible-tmp-1564023350.3869421-223113472194736/AnsiballZ_command.py && sleep 0'"'"''
<snip>
localhost | CHANGED | rc=0 >>
Python 2.7.16
Key takeaways
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With