Variable Management

Hello everyone!

We’re currently preparing to set up our configuration management with Ansible from scratch. We have decided on using dynamic inventory for AWS with the amazon.aws.aws_ec2 inventory plugin, grouping instances by their tags.

We need to install monit (which collects some metrics for monitoring) on all instances, but with different values for each of them. The point is, some values are common for all instances and some are specific.

For example, all instances should have a check for disk usage on the root mountpoint, but only a subset of hosts should check for the /var/cache mountpoint.

The monit role we want to use, however, wouldn’t allow us to specify common and specific values because it only accepts one variable with a list of checks.

That means if we set it up in the following way (pseudocode):

# group_vars/tag_project_myproject
# All hosts are in this group

monit_checks:
- root filesystem

# group_vars/tag_group_subset
# not all hosts are in this group

monit_checks:
- var filesystem

Only one of the values would apply. We don’t want to concern ourselves with merging variables inside our playbooks, as that feels hacky and cumbersome. What would be the appropriate way to achieve this with Ansible, that is, how can we avoid duplicating the same variables on multiple hosts and specifying one common set of variables and performing overwrites as needed?

Thank you!

Best,

Marco Godinho