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:
-
create: Spins up the test instances, e.g., Podman containers as defined in the document.
-
prepare: Prepares the instances, which can include installing dependencies or configuring the environment before applying the role.
-
converge: Applies the role or playbook to the test instances, configuring them as intended.
-
idempotence: Runs the playbook again to verify that no changes are made on a second run, ensuring idempotency.
-
verify: Executes any assertions or tests defined in
verify.yml
to confirm the expected state and functionality. -
destroy: Tears down the test instances, cleaning up the environment.
Note
|
Idempotency is checked automatically by Molecule during the |
This document is supported by the https://github.com/rstyczynski/ansible-collection-howto
repository, where all the code presented here is available for use.