I've written an ansible script to install a web application made of several components. While I've originally written it as a collection of several roles, I'm wondering whether this is the best way to do that.
My end goal is to have clear default variables that can be overwritten in a playbook (ideally in a single file).
The components rely on variables that must remain the same across several of them. As a result, the roles for the components cannot be self-sufficient. If I set defaults inside roles, then I can't run the playbook on a single component using tags as Ansible will complain it's missing some variables. I haven't found a non-hacky way to define default variables at the collection level. I could define a role whose sole purpose is to define defaults for common variables, but that seems very hacky. I've also thought about turning the collection into a single role, but then I lose possibilities such as selecting which components to install. What's the proper way to handle such a situation?
By the way, the collection is https://gitlab.com/cmatte/ansible-pglister/.
I'll do my best to answer your questions
Ansible Collections are not meant to store any variables or defaults, but are rather a way of packaging several roles/playbooks into a same logical namespace.
I highly suggest that your roles vars are not dependant from other roles vars / default. Roles should run independently. If there is dependency across your roles then you might want to merge them into a single role, or use a playbook to manage the dependencies.
I am not sure what is the purpose here but your role should be run in it's entirety - you should avoid pattern such as "I want to run only X part of this role/playbook" - Your roles/playbooks should be idempotent. If you want to have a set of different actions (install/uninstall/upgrade), then each action should be an ansible playbook that make the appropriate role calls.
By looking quickly at your repo, it seems like you only need one role to achieve what you want to do. I would convert your roles to playbooks unless you want to reuse them for other purpose.
Hope it helps!