I just noticed a curious difference between how we use mergevars
and the way community.general.merge_variables
is documented. The latter seems to be oriented toward a common suffix for selecting variables to merge. In practice, we use a common prefix.
For example, in our Linux systems project ./roles/sssd/tasks/main.yml
file, we have this variable definition:
sssd_allow_groups: "{{ lookup('mergevars',
'sssd_allow_groups_default',
regex='^sssd_allow_groups_') | sort | unique }}"
In ./roles/sssd/defaults/main.yml
we define the variable sssd_allow_groups_default
which gets merged first. In various ./group_vars/...
files we define sssd_allow_groups_hostgroupfoo
, sssd_allow_groups_hostgroupbar
, sssd_allow_groups_hostgroupbaz
, etc., and similarly in some ./host_vars/...
files.
This is just convention of course; one could match on either suffix or prefix with either mergevars
or c.g.merge_variables
. It just struck me as odd that we had chosen to use prefix way back in the day. I’m almost certain we never even considered matching on a common suffix. Especially since variables specifically relevant to local roles all start with the roles’ names.