Append Variables from one group to another

Hi all! Is it possible to append variables from one group to another? Here is an example below for better clarity:

Group Variables

An array that lists users from a “core” group that will be applied to all servers:

  1. CORE group
  2. User1
  3. User2

There would be another group for “customer” that would have:

  1. CUSTOMER Group
  2. User3
  3. User4
    Conditionals

If the server DOES belong to the customer group, it should include the following users:

  1. User1

  2. User2

  3. User3

  4. User4
    If the server does NOT belong to the “customer” group, it would just be the following users:

  5. User1

  6. User2
    Suggestions
    Any thoughts? Tybstar on IRC recommended “set operation filters” that could work but even mentioned that it could get messy – especially if I start adding additional groups (Customer2, Customer3, etc.). I figured I would bounce a post off of here incase there are any additional thoughts or suggestions.

Thanks!

If you use a dictionary rather than a list, then you can merge them, giving you what you want.
(you’ll need the setting ‘hash_behaviour=merge’ in your ansible.cfg)

This allows you to have group variables like

in core group