How to share group_vars between different inventories in Ansible?
<p>The Ansible best practices documentation <a href="http://docs.ansible.com/ansible/playbooks_best_practices.html#alternative-directory-layout" rel="noreferrer">recommends</a> to separate inventories:</p>

<pre>
inventories/
   production/
      hosts.ini           # inventory file for production servers
      group_vars/
         group1           # here we assign variables to particular groups
         group2           # ""
      host_vars/
         hostname1        # if systems need specific variables, put them here
         hostname2        # ""

   staging/
      hosts.ini           # inventory file for staging environment
      group_vars/
         group1           # here we assign variables to particular groups
         group2           # ""
      host_vars/
         stagehost1       # if systems need specific variables, put them here
         stagehost2       # ""
</pre>

<p>My staging and production environments are structured in the same way. I have in both environments the same groups. And it turns out that I have also the same group_vars for the same groups. This means redundancy I would like to wipe out.</p>

<p>Is there a way to share some group_vars between different inventories?</p>

<p>As a work-around I started to put shared group_vars into the roles.</p>

<pre><code>my_var:
  my_group:
    - { var1: 1, var2: 2 }
</code></pre>

<p>This makes it possible to iterate over some vars by intersecting the groups of a host with the defined var:</p>

<pre><code>with_items: "{{group_names | intersect(my_var.keys())}}"
</code></pre>

<p>But this is a bit complicate to understand and I think roles should not know anything about groups.</p>

<p>I would like to separate most of the inventories but share some of the group_vars in an easy to understand way.  Is it possible to merge global group_vars with inventory specific group_vars?</p>