Skip to content
Latchkey

Molecule "The requested Python interpreter could not be found" in CI

Ansible modules run through a Python interpreter on the target. On a minimal Molecule instance with no Python, interpreter discovery fails and every module task errors before doing any work.

What this error means

Converge fails with "The module failed to execute correctly ... The requested Python interpreter could not be found" or "/usr/bin/python3: not found" on the instance.

Molecule
fatal: [instance]: FAILED! => {"msg": "The module failed to execute correctly,
you probably need to set the interpreter.\nSee stdout/stderr for the exact error.
/bin/sh: 1: /usr/bin/python3: not found"}

Common causes

The base image ships no Python

A slim image (alpine, distroless-like) has no Python, so Ansible cannot find an interpreter to run modules.

Interpreter discovery points at the wrong path

Python exists but under a different path than discovery expects, and no ansible_python_interpreter was set.

How to fix it

Bootstrap Python in prepare with raw

Install Python before modules run, using the raw module which needs no Python.

molecule/default/prepare.yml
# molecule/default/prepare.yml
- hosts: all
  gather_facts: false
  tasks:
    - raw: which python3 || (apk add --no-cache python3) || (apt-get update && apt-get install -y python3)
      changed_when: false

Set the interpreter explicitly

Point Ansible at the real interpreter path for the image.

molecule/default/molecule.yml
provisioner:
  name: ansible
  inventory:
    host_vars:
      instance:
        ansible_python_interpreter: /usr/bin/python3

How to prevent it

  • Use ansible-ready images or bootstrap Python in prepare.
  • Set ansible_python_interpreter for non-standard images.
  • Test against the same image the role targets in production.

Frequently asked questions

What causes ""requested Python interpreter could not be found""?
A slim image (alpine, distroless-like) has no Python, so Ansible cannot find an interpreter to run modules.
How do I fix "requested Python interpreter could not be found"?
Install Python before modules run, using the raw module which needs no Python.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card