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.
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
- hosts: all
gather_facts: false
tasks:
- raw: which python3 || (apk add --no-cache python3) || (apt-get update && apt-get install -y python3)
changed_when: falseSet the interpreter explicitly
Point Ansible at the real interpreter path for the image.
provisioner:
name: ansible
inventory:
host_vars:
instance:
ansible_python_interpreter: /usr/bin/python3How to prevent it
- Use ansible-ready images or bootstrap Python in prepare.
- Set
ansible_python_interpreterfor non-standard images. - Test against the same image the role targets in production.