How do you keep Molecule runs fast in CI?
IntermediateProductionTesting, CI/CD and Quality
Answer
- Use prebuilt images with Python and systemd already installed (
pre_build_image: true), not a Dockerfile built on every run. - Run only the scenarios of roles that changed: compute changed paths with
git diff --name-only origin/main...and feed the list to a CI matrix. - Run platforms and roles in parallel jobs rather than one long job.
- Cache Galaxy collections (
~/.ansible/collections) and pip wheels between jobs. - Keep
prepare.ymlsmall; bake slow prerequisites into the test image. - Use
molecule convergeandmolecule verifylocally during development, and the fullmolecule testonly in CI.
A role test that takes 15 minutes gets skipped by humans. Under 3 minutes it gets run.
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?BeginnerHow is a Molecule scenario laid out, and what does `molecule test` actually run?IntermediateDocker, Podman or real VMs as the Molecule driver: how do you choose?Advanced