I am working on adding tests to all my existing Ansible roles using Molecule. My existing Ansible playbooks utilize levels of variables like such:
file: playbook_dir/group_vars/all
contents: global variables, applicable to all everything (hosts, inventories etc.)
file: playbook_dir/inventories/<inventory>/group_vars/all
contents: variables applicable to all hosts in this inventory.
file: playbook_dir/inventories/<inventory>/group_vars/<group>
contents: variables applicable only to this group.
When setting up Molecule for my existing roles, I need access to at the very least the 'global variables' (first in my list), I managed to achieve this by adding links, like such:
provisioner:
name: ansible
inventory:
links:
group_vars: ../../../../group_vars # These are the 'global' group_vars as described above.
So far so good, right. However, there are several roles that require variables to be set which are not part of the 'global' group_vars; i.e. inventory specific ones. I've found that:
- The links only allow a single link to be made, so linking to multiple group_vars does not seem to be an option.
- inventory.links.group_vars and inventory.group_vars are mutual exclusive.
My question: How can I re-use my existing 'global variables', but also either a) use existing inventory specific group_vars, or b) define inventory specific group_vars?