Interview Prep/Ansible/Fundamentals and Architecture

How does Ansible choose the Python interpreter on a target, and how do you override it?

AdvancedConceptFundamentals and Architecture
Answer

By default interpreter_python=auto: Ansible runs a discovery script on the target that looks for known Python paths (/usr/bin/python3, /usr/libexec/platform-python and so on), picks the best one, and caches the result in the discovered_interpreter_python fact.

Override per host/group/play with ansible_python_interpreter, or globally in ansible.cfg:

[defaults]
interpreter_python = /usr/bin/python3

Set it explicitly when the module needs libraries from a specific venv (for example boto3 in a virtualenv) or when auto discovery picks a Python that lacks python3-apt/libselinux-python.

All Ansible questions Roadmap: Ansible

More on Fundamentals and Architecture