4. Executing playbook test
Running a test is super simple, and means just invoking molecule with test
and the name of the test scenario. As the test is Podman-based, it’s assumed that the Podman machine is available; in case of errors, verify Podman with podman info
.
molecule test -s apache1_debian
Running the test can take some time and produces long log output, as Molecule executes a series of stages: dependency
, cleanup
, destroy
, syntax
, create
, prepare
, converge
, idempotence
, verify
, cleanup
, and finally destroy
.
Note
|
To reduce unnecessary error messages in the logs, I explicitly disabled the |
4.1 Preparation stages
Let’s group these stages into practical categories. The first group is preparation, which sets up the test environment. In this phase, the Podman instance is prepared and started, dependencies are installed according to the test’s requirements.yml
, and the converge
play syntax is checked.
molecule dependency -s apache1_debian
molecule destroy -s apache1_debian
molecule syntax -s apache1_debian
molecule create -s apache1_debian
4.2 Configure and verify stages
The second phase is the main test execution. The converge
step runs your playbook, applying all intended changes. Next, the idempotence
step reruns the playbook to ensure that no further changes are made - verifying that your playbook is truly idempotent. If any changes are detected during this step, the idempotence test will fail, however the test pipeline will not be stopped. Finally, the verify
step runs assertions to confirm that the system is in the desired state. Note that during regular repetitive tests supporting play development, you will use these three steps.
molecule converge -s apache1_debian
molecule idempotence -s apache1_debian
molecule verify -s apache1_debian
4.3 Cleanup stage
Finally, when the test is done, the Podman instance needs to be removed. The destroy step takes care of this.
molecule destroy -s apache1_debian