Tests

The philosophy to test is:

Where roles are tested

Every role is tested twice, on GitHub Actions (.github/workflows/molecule.yml) and on GitLab CI (.gitlab-ci.yml). GitLab is a mirror of GitHub, it picks up every push a few minutes later and runs its own pipeline, on amd64 runners. A difference between the two is interesting, it usually points at the CI platform and not at the role.

These files are generated by ansible-generator from meta/main.yml and a few other files, so all roles are tested the same way.

Distributions

The matrix of distributions comes from the platforms in a role’s meta/main.yml. A role only lists the platforms it supports. These are the container images that can be used:

See distribution relations for the images, tags and branches.

Unit tests

To test an Ansible role, Molecule runs it in containers. The containers run systemd (OpenRC on Alpine), so services can really be started. Molecule runs these steps:

  1. dependency: install the roles and collections the role needs (requirements.yml).
  2. create: start a container.
  3. prepare: run the roles that have to run before this role (molecule/default/prepare.yml).
  4. converge: run the role (molecule/default/converge.yml).
  5. idempotence: run the role again, nothing may change.
  6. verify: test the intent of the role, for example that a port is open or that the installed software shows its version (molecule/default/verify.yml).
  7. destroy: remove the container.

The tests use the latest release of ansible-core. This verifies that the role does its job, but does not ensure that it works in combination with all other roles, only with the roles in prepare.yml.

Lint

Every pull request is linted with ansible-lint (and the pre-commit hooks). Lint has to pass before the Molecule job runs. See the style guide.

Time based unit tests

Because distributions, Molecule, and Ansible change over time, a monthly test is done to all roles. The first letter of the role determines the day of the month it’s tested: a runs on the 1st, b on the 2nd, up to z on the 26th. For example ansible-role-example starts with an e, so it runs on the 5th of the month.

When does what run

Event GitHub Actions GitLab CI
Pull request lint only -
Push to master lint and Molecule lint and Molecule (after the mirror syncs)
Monthly schedule Molecule Molecule
Manually workflow_dispatch run pipeline

Known limits