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"
}