Ansible 2.2 features a tech preview of Python 3 support. This topic discusses how you can test to make sure your modules and playbooks work with Python 3.
Technology preview features provide early access to upcoming product innovations, enabling you to test functionality and provide feedback during the development process. Please be aware that tech preview features may not be functionally complete and are not intended for production use. To report a Python 3 bug, please see Community Information & Contributing.
python3. For example:
python3 /usr/bin/ansible localhost -m ping python3 /usr/bin/ansible-playbook sample-playbook.yml
ansible_python_interpreterconfiguration option is usually set per-host as an inventory variable associated with a host or group of hosts:
# Example inventory that makes an alias for localhost that uses python3 [py3-hosts] localhost-py3 ansible_host=localhost ansible_connection=local [py3-hosts:vars] ansible_python_interpreter=/usr/bin/python3 See the :ref:`inventory documentation <inventory>` for more information.
ansible localhost-py3 -m ping ansible-playbook sample-playbook.yml
Note that you can also use the
-e command line option to manually
set the python interpreter when you run a command. For example:
ansible localhost -m ping -e 'ansible_python_interpreter=/usr/bin/python3' ansible-playbook sample-playbook.yml -e 'ansible_python_interpreter=/usr/bin/python3'
If you find a bug while testing modules with Python3 you can submit a bug report on Ansible’s GitHub project. Be sure to mention Python3 in the bug report so that the right people look at it.
If you would like to fix the code and submit a pull request on github, you can refer to Ansible and Python 3 for information on how we fix common Python3 compatibility issues in the Ansible codebase.