Ansible "MODULE FAILURE ... /usr/bin/python: not found" in CI
Ansible copied a module to the remote host and tried to run it with a Python interpreter that does not exist there. Modern targets ship python3 rather than /usr/bin/python, so the module fails before doing any work.
What this error means
A task fails with "MODULE FAILURE" and the remote stderr shows "/usr/bin/python: not found" or "/bin/sh: python: command not found".
ansible
fatal: [host1]: FAILED! => {"changed": false, "module_stderr": "/bin/sh: 1:
/usr/bin/python: not found\n", "msg": "MODULE FAILURE", "rc": 127}Common causes
The target only has python3
The host provides /usr/bin/python3 but no python, so the default interpreter path resolves to nothing.
A minimal image with no interpreter on PATH
A slim container or distroless-like target lacks any Python where Ansible expects it.
How to fix it
Set ansible_python_interpreter
- Find the interpreter on the target (
which python3). - Set
ansible_python_interpreterfor that host or group. - Re-run so the module uses the real interpreter.
inventory
# inventory
[web]
host1 ansible_python_interpreter=/usr/bin/python3Use auto discovery
Let Ansible find a working interpreter automatically when the path varies across hosts.
ansible.cfg
# ansible.cfg
[defaults]
interpreter_python = auto_silentHow to prevent it
- Set
ansible_python_interpreter=/usr/bin/python3for modern hosts. - Use
interpreter_python = auto_silentfor mixed fleets. - Ensure a Python interpreter is present on target images.
Related guides
Ansible "Unexpected Exception ... cannot import name" in CIFix Ansible "ERROR! Unexpected Exception ... cannot import name X" in CI - a Python dependency version mismat…
Ansible "Failed to connect to the host via ssh: Permission denied (publickey)" in CIFix Ansible "FAILED! ... Failed to connect to the host via ssh: Permission denied (publickey)" in CI - the ru…
Ansible apt "Could not get lock /var/lib/dpkg/lock" in CIFix Ansible apt "Failed to lock apt for exclusive operation ... Could not get lock /var/lib/dpkg/lock-fronten…