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.
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