Questions about using molecule for testing roles in collection #2965
Replies: 2 comments 2 replies
-
I'm not sure, if this relevant for you, but I'd the same problem today and all the documentation in the web is either very old or not very easy. In fact molecule doesnt support testing roles within collections (or at least not very well). My workaround: I've created a prepare.yml within molecule default profole, that should test my roles within the collection. This prepare script copies the current content of the collection to the first location of ANSIBLE_COLLECTION_PATH environment var, which is always present during runtime of molecule.
This seems to work well without installing the collection first with ansible-galaxy, also it runs well with Github Actions. |
Beta Was this translation helpful? Give feedback.
-
We use another approach, that some might find simpler.
Whatever ansible-playbook command one runs in |
Beta Was this translation helpful? Give feedback.
-
My Development Setup
I created a collection from ansible-galaxy collection init template
Inside that collection, I have built code for a few roles and some playbooks that invoke features provided by roles in that collection
Using MOCK/unittest available in ansible galaxy general collection, I created few unit tests to test my modules and also writing some playbooks to do integration test.
Queries for CI test with Molecule
How can I invoke my based python unit tests (based on https://github.com/ansible-collections/community.general/tree/main/tests/unit/compat) from inside the Molecule for testing?
From whatever little documentation available with 'Molecule + collections' they are using 'TestInfra',
Can you kindly share your thoughts if I need to rewrite my mock/unittest based unit tests if I have to adhere/use TestInfra?
Can we test the collection with Molecule (and the roles/modules/playbooks) without 'installing' the collection? (whose default path is ~/.ansible
If I make my custom Docker image (with collection installed in it) can I run molecule tests inside docker? If yes can you provide an example of a molecule.yml?
Thanks and Regards
Sriram
Beta Was this translation helpful? Give feedback.
All reactions