Skip to content
Latchkey

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

  1. Find the interpreter on the target (which python3).
  2. Set ansible_python_interpreter for that host or group.
  3. Re-run so the module uses the real interpreter.
inventory
# inventory
[web]
host1 ansible_python_interpreter=/usr/bin/python3

Use auto discovery

Let Ansible find a working interpreter automatically when the path varies across hosts.

ansible.cfg
# ansible.cfg
[defaults]
interpreter_python = auto_silent

How to prevent it

  • Set ansible_python_interpreter=/usr/bin/python3 for modern hosts.
  • Use interpreter_python = auto_silent for mixed fleets.
  • Ensure a Python interpreter is present on target images.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →