1

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:

  1. The links only allow a single link to be made, so linking to multiple group_vars does not seem to be an option.
  2. 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?

darkl0rd
  • 31
  • 1
  • 4

1 Answers1

0

You can define inventory group_vars specific to you molecule test(s) directly in molecule.yml. This also works for host_vars

Ref: https://molecule.readthedocs.io/en/stable/configuration.html#id22 (search for 'inventory:' on the page).

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
  • 4
    Yes, but when you do that, you cannot link to an existing vars file anymore. My question is whether there is a way to do both. – darkl0rd Dec 30 '19 at 06:06