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

Ansible verifier or Testinfra: which do you use for Molecule `verify`?

IntermediateProductionTesting, CI/CD and Quality
Answer

Both work. The Ansible verifier (verify.yml with assert, uri, command + changed_when: false) keeps everything in one language, so the whole team can write tests. Testinfra (pytest) is more expressive for complex assertions and gives nicer failure output.

# molecule/default/tests/test_default.py  (verifier: name: testinfra)
def test_nginx_running(host):
    svc = host.service("nginx")
    assert svc.is_running and svc.is_enabled

def test_listens_on_443(host):
    assert host.socket("tcp://0.0.0.0:443").is_listening

In production we default to the Ansible verifier for team-wide roles and allow Testinfra where a team is already comfortable with pytest. The bigger rule is what to test: behaviour (port answers, config parses), not that Ansible wrote the file it was told to write.

All Ansible questions Roadmap: Ansible

More on Testing, CI/CD and Quality