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.
More on Fundamentals and Architecture
What is Ansible and what problem does it solve?BeginnerWhat does "agentless" mean in Ansible?BeginnerWhat are the requirements for the control node?BeginnerWhat does a managed node need?BeginnerIs Ansible push-based or pull-based?BeginnerWalk through what happens when you run `ansible-playbook site.yml`.Intermediate