How is a Molecule scenario laid out, and what does `molecule test` actually run?
IntermediateProductionTesting, CI/CD and Quality
Answer
A scenario lives in roles/<role>/molecule/<scenario>/ and contains molecule.yml (driver, platforms, provisioner, verifier), converge.yml (applies the role), optionally prepare.yml (pre-state such as repos or users) and verify.yml (assertions).
molecule test runs the full sequence: dependency → cleanup → destroy → syntax → create → prepare → converge → idempotence → side_effect → verify → cleanup → destroy.
# molecule/default/molecule.yml
driver:
name: docker
platforms:
- name: rocky9
image: geerlingguy/docker-rockylinux9-ansible:latest
pre_build_image: true
provisioner:
name: ansible
verifier:
name: ansible
The idempotence step re-runs converge and fails if anything reports changed, which is the single most valuable check Molecule gives you.
More on Testing, CI/CD and Quality
What does a testing pyramid look like for Ansible code?BeginnerHow do you roll out `ansible-lint` profiles across a team without blocking everyone?IntermediateWhen do you use `skip_list`, `warn_list` and `# noqa`?IntermediateHow do you set up pre-commit hooks for an Ansible repo?BeginnerDocker, Podman or real VMs as the Molecule driver: how do you choose?AdvancedHow do you test roles that manage systemd services inside Molecule containers?Advanced