I hope to collect bits and pieces on how to setup Ansible Collection project for local development and testing with Molecule.
- ~/code/github.com/user/namespace/
- .skeleton/
- collection-a/
- collection-b/
- collections/
- environments/
- development/
- production/
- .ssh/
- group_vars/
- host_vars/
- hosts
- molecule/
- role-a/
- role-b/
- playbooks/
- plugins/
- roles/
- role-a/
- role-b/
- scripts/
There are 3 ways how to handle role meta dependencies:
- Publish collection to Ansible Galaxy
- Push collection to the remote Git repository
- Use local collections
This means that all dependencies are available locally and Molecule does not need to ping the Web. To make this working there are few requirements:
-
All dependencies should be cloned into
~/code/github.com/user/ansible/collection-b/collections/ansible_collections/collection-name
This should be done even for the collection or roles which are part of thecollection-a
orcollection-b
if there are roles which deppends on each other. But inter-role dependencies is considered as a bad practice and the playbooks should be used to glue several roles together. You can useln -s $PWD/roles $PWD/collections/ansible_collections/namespace/collection-b/roles
to create the symlinks to the actual roles. Or you can just copy them, but that will lead to the confussion when you will forget to update those. -
molecule.yaml#provisioner:env:ANSIBLE_COLLECTION_PATH: "./collections"
should be set.I believe you could also create symlink from
~/code/github.com/user/namespace/
to~/.ansible/collections/ansible_collections/namespace
and in this case I think you can omit theANSIBLE_COLLECTION_PATH
variable. I should check that. https://docs.ansible.com/ansible/devel/dev_guide/developing_collections_contributing.html#hacking-collections
Since I wrote this, I do things bit differently. All my collections are just part of single "ansible" Git repository under
./collections/ansible_collections
directory.