Interview Prep/Ansible/Testing, CI/CD and Quality

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:

  1. Static: yamllint, ansible-lint, ansible-playbook --syntax-check. Seconds, every push.
  2. Role tests: Molecule converges each role in containers, checks idempotence and runs verify. Minutes, on every PR touching the role.
  3. Integration: the full playbook against a short-lived staging environment (real VMs, real cloud). On merge to main or nightly.
  4. Production dry run: --check --diff against 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.

All Ansible questions Roadmap: Ansible

More on Testing, CI/CD and Quality