Automation without testing is fragile. To ensure that playbooks, roles, and collections behave reliably across different environments, the Ansible ecosystem provides the Molecule testing tool.

Molecule defines a clear pipeline with several phases that guide the testing of Ansible content:

  1. create: Spins up the test instances, e.g., Podman containers as defined in the document.

  2. prepare: Prepares the instances, which can include installing dependencies or configuring the environment before applying the role.

  3. converge: Applies the role or playbook to the test instances, configuring them as intended.

  4. idempotence: Runs the playbook again to verify that no changes are made on a second run, ensuring idempotency.

  5. verify: Executes any assertions or tests defined in verify.yml to confirm the expected state and functionality.

  6. destroy: Tears down the test instances, cleaning up the environment.

Note

Idempotency is checked automatically by Molecule during the idempotence phase, helping to catch unintended changes or side effects in your playbook.

This document is supported by the https://github.com/rstyczynski/ansible-collection-howto repository, where all the code presented here is available for use.