What does a testing pyramid look like for Ansible code?
BeginnerProductionTesting, CI/CD and Quality
Answer
Cheap, fast checks run on every commit; slow, expensive checks run less often. In production we use four layers:
- Static:
yamllint,ansible-lint,ansible-playbook --syntax-check. Seconds, every push. - Role tests: Molecule converges each role in containers, checks idempotence and runs
verify. Minutes, on every PR touching the role. - Integration: the full playbook against a short-lived staging environment (real VMs, real cloud). On merge to main or nightly.
- Production dry run:
--check --diffagainst prod with a limit, reviewed before the real change.
Most bugs are caught at layers 1 and 2. Layer 3 catches what containers cannot: kernels, systemd quirks, networking, cloud IAM.
More on Testing, CI/CD and Quality
How 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?AdvancedHow do you test roles that manage systemd services inside Molecule containers?Advanced