how to choose a python interpreter for Ansible playbook?

Question:

I have python2.7 and python3.5 in my ansible server , while executing playbooks it is using python2.7. I wanted ansible to use python3.5 when executing playbooks.

But still, ansible is not running python3.

Answer:

If you want to set the Python interpreter for individual hosts and groups, set the ansible_python_interpreter inventory variable.

If however, you want to set the Python interpreter for global use, then set the interpreter_python key in the [defaults] section in the configuration file ansible.cfg.

For a complete list of possible values for the two options above, please see: https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html

Also see this example for usage of ansible_python_interpreter: https://docs.ansible.com/ansible/2.4/python_3_support.html , section “Testing Python 3 module support”.

Leave a Reply