feat: add ansible task testing infrastructure based on Docker and pytest
This complements the existing AMI tests in testinfra by providing a faster feedback loops for Ansible development without requiring a full VM.
We are also using testinfra to validate that the Ansible tasks have the desired effect.
It is based on Docker, it can be run locally (e.g. macOS) or in CI.
Note that this approach is not intended to replace the AMI tests, but rather to provide a more efficient way to test Ansible tasks during development.
You can run the tests using nix run -L .\#ansible-test
@hunleyd I realize it may not yet be documented very well, but in order for you to get 1:1 parity with the linter in this PR, you would want to:
- check out the branch test/ansible-tasks
- run
nix develop -c ansible-lint <the rest of your command here>
By doing it this way, you'll then use the same ansible lint version in this PR, and the same configuration.
This helps avoid the "works on my machine" problem that may come up if we install ansible lint and tools from brew install etc. We can get 1:1 with what other developers are doing with nix develop -c ansible-lint <the rest of your command here> plus what the CI job is doing which will also use the exactly same version and setup. I hope that helps, and thanks as ever for reviewing these PR.
Also we have pre-commit hook in the dev shell. So if you start the dev shell using nix develop, pre-commit hook will be register and triggered when you commit/push but you can also run it manually inside the devshell (just like the CI will do): pre-commit run --all..
The pre-commit hook configuration is defined in nix/hooks.nix and as you will see we only validates github action, ansible-lint and formatting (defined in nix/fmt.nix) for the moment.