How do you write `verify` tests that are actually useful?
IntermediateProductionTesting, CI/CD and Quality
Answer
Test outcomes, not the steps Ansible already reported. Checking that /etc/nginx/nginx.conf exists after a template task proves nothing new.
Useful checks:
- The service answers on the expected port and protocol with the expected response.
- The config passes the application's own validator (
nginx -t,sshd -t,promtool check config). - Security properties hold: file owner and mode, the service does not run as root, the port is not open on the public interface.
- A restart or reboot leaves the service running (enabled, not just started).
- name: App responds with expected version
ansible.builtin.uri:
url: http://localhost:8080/version
return_content: true
register: v
failed_when: app_version not in v.content
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