Tests folder in skeleton created by ansible-galaxy

Hi,

Thanks for this incredible project and community.

I run

ansible-galaxy role init mwe

and it created

mwe/
├── defaults
│   └── main.yml
├── files
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── README.md
├── tasks
│   └── main.yml
├── templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars
    └── main.yml

I’m trying to understand a little better how to use the tests folder or if I should use the Molecule framework.

Any recommendation? Thanks!

In the tests folder I put complete test playbooks that can be executed on any host without any requirements besides the role intself, I execute them on localhost. This is just another source of quick tests for the role, I design these playbooks specifically for that purpose. I have also molecule and other tests.

As far as I know there is no community or ansible standard what to put there, moreover almost all the roles I’ve seen have no content in the tests folder.

@kks , how exactly do you invoke such test playbooks?

I’ve got a few roles with some ad hoc tests in ./tests/test.yml, but I end up with a little forest of unreproducible symbolic links and inconsistent one-off notes about how to run the tests. I’ve never figured out how those playbooks under ./tests/ are supposed to be run.

I package all ansible content inside collections and I have unconventional repo structure.
I put collections inside repo like this

ansible_collections/<collection_namespace>/<collection_name>/roles/<role_name>

I think in several places already I’ve advocated for this kind of folders structure - from my point of view it simplifies a lot of things.

In the tests folder inside role I use FQCN for the role ..<role_name>

I simply run all the yaml files with the name test_*.yml from tests folders. Find them with find command and run them with ansible-playbook from the root of the project with environment variable ANSIBLE_COLLECTIONS_PATH=.:$ANSIBLE_COLLECTIONS_PATH. Ansible find all the collections inside this repo first in that case. So I just have to update the role or test inplace without commit or installation and all tests (from tests folder) will run correctly.

Just for refenrence
https://docs.ansible.com/projects/ansible/latest/reference_appendices/config.html#collections-paths