Skip to content

Conversation

@jfroche
Copy link
Collaborator

@jfroche jfroche commented Oct 31, 2025

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

@jfroche jfroche force-pushed the test/ansible-tasks branch 8 times, most recently from a79867e to 7fad1eb Compare October 31, 2025 17:30
@jfroche jfroche marked this pull request as ready for review October 31, 2025 17:30
@jfroche jfroche requested review from a team as code owners October 31, 2025 17:30
Copy link
Contributor

@hunleyd hunleyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly ansible-lint fixups

@jfroche jfroche requested a review from hunleyd November 11, 2025 15:37
ansible.builtin.user:
name: 'nginx'
state: 'present'
name: nginx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quote dropping is intentional?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not is my guess. maybe needs rebase

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran ansible-lint --fix and it automatically removes unnecessary quotes to follow YAML best practices for improved readability (https://docs.ansible.com/projects/lint/rules/yaml/#yaml).

@samrose
Copy link
Collaborator

samrose commented Nov 11, 2025

@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:

  1. check out the branch test/ansible-tasks
  2. 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.

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`
Configure pre-commit hook to run ansible-lint on test playbooks and their dependencies.
Since test playbooks include tasks from existing task files, ansible-lint automatically validates those dependencies as well.
@jfroche
Copy link
Collaborator Author

jfroche commented Nov 11, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants