title: Ansible access same group vars different children host groups
body: <p>I am trying to run a role which loops based on a parent group (or parent of parent group) with two or more child groups with certain number of hosts. The two child groups have same group_vars so I tried to define the group_vars separately for each child group but executing the role only inherits group_vars from either of the child group. I understand about the Ansible variable merging but my specific use case (want to run same role at different hierarchies of host groups) needs to load the group_vars for each child group when I try to run the role in loop based on the parent group or parent of parent group. Please help in this regard.</p>
  
  <p>Inventory File: </p>
  
  <pre><code>    [test1]
      server1
      server2
  
      [test2]
      server3
      server4
  
      [test:children]
      test1
      test2
  
      [test0:children]
      test
  </code></pre>
  
  <p>/group_vars/test1.yml:</p>
  
  <pre><code>   param1: 1234
     param2: 3456
  </code></pre>
  
  <p>/group_vars/test2.yml:</p>
  
  <pre><code>   param1: 7867
     param2: 0987
  </code></pre>
  
  <p>role/tasks/main.yml:</p>
  
  <pre><code>- uri:
      url: http://{{ item }}:{{ hostvars[groups['test'][0]]['param1'] }}/{{ hostvars[groups['test'][0]]['param2'] }}/
      return_content: yes 
    register: response
    ignore_errors: true
    loop: "{{ groups['test'] }}"
  </code></pre>