How would you test a role in CI before it reaches production?
IntermediateScenarioPerformance, Testing and CI/CD
Answer
Situation read → Automated role testing.
What I'd do → Use Molecule with a container driver (Docker/Podman).
# molecule/default/molecule.yml
driver: { name: docker }
platforms:
- name: ubuntu24
image: geerlingguy/docker-ubuntu2404-ansible
pre_build_image: true
command: ""
privileged: true
provisioner: { name: ansible }
verifier: { name: ansible }
molecule test # create, converge, idempotence, verify, destroy
Why → The sequence proves the role applies, is idempotent, and meets assertions.
Interview tip → Add a matrix of OS images to check portability.
More on Performance, Testing and CI/CD
A playbook that touches 200 hosts takes 40 minutes. Where do you start tuning?IntermediateYou install 15 packages with a loop and it is slow.BeginnerWhat would a Molecule `verify.yml` check for an Nginx role?IntermediateMolecule's idempotence step fails. How do you find the offending task?IntermediateDesign a CI pipeline for an Ansible repo.Advanced`--check` shows no change but the real run changes things. Why?Advanced