Ansible ignoring ansible_python_interpreter as command line parameter

0

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

ansible python python-3.x ubuntu
2021-11-23 17:22:13
1

0

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.

2021-11-23 17:27:15

Ah, "The Ansible control process always uses the Python interpreter it was installed under;", that explains some of the behavior I've seen. Any idea how to check under which version it was installed?
U880D

Run ansible --version
flowerysong

There I found the reason for some of the behavior: ansible python module location = /usr/lib/python2.7/site-packages/ansible. We may need to follow Ansible: How to change python version?
U880D

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................