How can I change my ansible_python_interpreter value on Ubuntu?
I downloaded and installed Python 2.7.12 from tar, and now it’s running by default outside of Ansible
JavaScript
x
3
1
# which python
2
/usr/local/bin/python
3
JavaScript
1
3
1
#python --version
2
Python 2.7.12
3
But when I try to set the variable, Ansible shows that it’s still using that newer version of Python (I need to use this older version to test)
JavaScript
1
10
10
1
# ansible-playbook --version -e "ansible_python_interpreter=/usr/local/bin/python"
2
3
ansible-playbook 2.5.1
4
config file = /home/fortinet/Downloads/ansible/playbooks/complete_provisioning/ansible.cfg
5
configured module search path = [u'/home/fortinet/Downloads/ansible/modules']
6
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
7
executable location = /usr/bin/ansible-playbook
8
python version = 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
9
root@ubuntu18:/home/fortinet/Downloads/ansible/playbooks/complete_provisioning#
10
Advertisement
Answer
It’s not possible to configure the version of Python used by Ansible on the controller.
ANSIBLE_PYTHON_INTERPRETER configuration parameter will set:
Path to the Python interpreter to be used for module execution on remote targets
The version of Python on controller depends on how Ansible has been built. For example
- Ubuntu 18.04 use Python 2.x
JavaScript
1
14
14
1
shell> grep DISTRIB_DESCRIPTION /etc/lsb-release
2
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
3
4
shell> dpkg -l | grep ansible
5
ii ansible 2.9.6-1ppa~bionic
6
7
shell> ansible --version
8
ansible 2.9.6
9
config file = /home/admin/.ansible.cfg
10
configured module search path = [u'/home/admin/.ansible/my_modules']
11
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
12
executable location = /usr/bin/ansible
13
python version = 2.7.17 (default, Nov 7 2019, 10:07:09) [GCC 7.4.0]
14
- Ubuntu 20.04 use Python 3.x
JavaScript
1
14
14
1
shell> grep DISTRIB_DESCRIPTION /etc/lsb-release
2
DISTRIB_DESCRIPTION="Ubuntu 20.04 LTS"
3
4
shell> dpkg -l | grep ansible
5
ii ansible 2.9.6+dfsg-1
6
7
shell> ansible --version
8
ansible 2.9.6
9
config file = /home/admin/.ansible.cfg
10
configured module search path = ['/home/admin/.ansible/my_modules']
11
ansible python module location = /usr/lib/python3/dist-packages/ansible
12
executable location = /usr/bin/ansible
13
python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]
14