Merging lists from group_vars

351 views
Skip to first unread message

Guy Knights

unread,
Jan 8, 2016, 8:12:14 PM1/8/16
to Ansible Project
Is there any way to merge lists from group_vars, much like hash_behaviour = merge, but for lists? From what I can tell, there is no explicit list_behaviour option I can set, but is there perhaps a manual way I can do this? I have a firewall configuration that uses group_vars to define the rules that are applied to each type of server, but now I'm trying to provision a server that is a member of multiple groups and it's only applying the rules from the last group that it belongs to. One way around my issue is to explicitly specify the rules in a host_vars file for this server only, but it feels a bit redundant; I'd really prefer if the rule lists could be combined from all groups this server belongs to as then I wouldn't have to go through each group and manually combine the lists in the host_vars file.

Thanks,
Guy

Jesse Schlüter

unread,
Jan 9, 2016, 2:53:37 AM1/9/16
to Ansible Project
I don't know whether this works in your case, but we worked around, by creating different lists and manually merging them together:

type_policy1:
  - whatever
  - your
  - policy
type_policy2:
  - list
  - looks
  - like

host_policy: '{{ policies1 + policies2 }}'
Reply all
Reply to author
Forward
0 new messages