Search code examples
pythonansible

How to choose a python interpreter for Ansible playbook?


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.

 in order:
   1 have set export path.
   2 also changed default interpreter path in ansible.cfg as well.
   3 have given specific interpretor path in hostsfile for particular host.

But still, ansible is not running python3.


Solution

  • 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".