Home > Blockchain >  Ansible ignoring ansible_python_interpreter as command line parameter
Ansible ignoring ansible_python_interpreter as command line parameter

Time:11-24

as you can see from the code snippet below, ansible's executable seems to be ignoring the ansible_python_interpreter variable. Without resorting to an inventory file (this is for a gitlab pipeline based on hashicorp's packer - which calls ansible), how could I enforce ansible to use whatever python version I have? In this case, it's an Ubuntu 18.04, so I want to switch from python-2.7 to python-3.6.

Another related cause couldto be the fact that ansibles pkg (policy?) always installs python-2.7 on bionic.

root@ubuntu18:~# ansible --version
ansible 2.9.27
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.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
  python version = 2.7.17 (default, Feb 27 2021, 15:10:58) [GCC 7.5.0]
root@ubuntu18:~# /usr/bin/python3.6 --version
Python 3.6.9
root@ubuntu18:~# ansible --version -e 'ansible_python_interpreter=/usr/bin/python3.6'
ansible 2.9.27
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.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
  python version = 2.7.17 (default, Feb 27 2021, 15:10:58) [GCC 7.5.0]
root@ubuntu18:~#

My last resort seems to be installing ansible using pip3, but that would require a significant rewrite of both the pipeline yaml and packer's json.

Any help would be greatly appreciated.

Cheers

CodePudding user response:

You have not provided any evidence that the parameter is being ignored. ansible_python_intepreter applies to the execution of modules on the targets, not to the execution of Ansible itself.

The Ansible control process always uses the Python interpreter it was installed under; the best way to change this is to change your install process.

  • Related