FreeKB - Ansible ansible_python_interpreter variable
Ansible - ansible_python_interpreter variable

Ansible uses version 2.x.x of Python to perform a number of different tasks and expects the Python command line tool to be located at /usr/bin/python. If a system has both version 2.x.x (e.g. /usr/bin/python) and version 3.x.x of Python (e.g. /usr/bin/python3), the ansible_python_interpreter variable can be used to tell Ansible to use /usr/bin/python or /usr/bin/python3.

There are many different ways to define a variable - refer to Getting Started with Variables.

The -e or --extra-vars command line option can be used, with both the ad-hoc ansible command

ansible localhost -m ping --extra-vars 'ansible_python_interpreter=/usr/bin/python3'

 

And with the ansible-playbook command.

ansible-playbook foo.yml --extra-vars 'ansible_python_interpreter=/usr/bin/python3'

 

Or the vars module could be used to define the ansible_python_interpreter variable.

NOTE - The gather_facts module must be set to true, which is the default setting of the gather_facts module. In other words, the gather_facts module must not be set to false.

---
- hosts: all
  vars:
    ansible_python_interpreter: /usr/bin/python
  tasks:
    - name: Return Python interpreter
      debug:
        msg: "Python interpreter = {{ ansible_python_interpreter }}"

 

Running this playbook should return the following.

TASK [debug]
ok: [server1.example.com] => {
    "msg: "Python interpreter = /usr/bin/python"
}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter f6bb1 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |