<p dir="auto">When a list of hashes are used as variables, ansible-playbook output is very verbose, printing out the full hash contents.  My working playbooks have longer variable files, so the terminal is constantly filled with useless information.</p>
<p dir="auto">Also, when used with debug, the output is full item results are printed to stdout. I'd like to have very short output of tasks using 'debug: var=' for administrators to easily see output of tasks (ie process_status=running/stopped, deployed software versions).</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---

- hosts: localhost
  vars:
    myapp:
      - name: app1
        somesetting: nope
        othersetting: yep
        dontyouhatepants: yep
      - name: app2
        somesetting: yep
        othersetting: yep
        dontyouhatepants: nope
  tasks:
  - name: just an echo
    shell: /bin/echo &quot;{{ item.name }}&quot;
    with_items: myapp
    register: echo
  - debug: var=item.stdout
    with_items: echo.results



$ ansible-playbook -i inv/TEST test.yml

PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [just an echo] **********************************************************
changed: [localhost] =&gt; (item={'dontyouhatepants': 'yep', 'name': 'app1', 'othersetting': 'yep', 'somesetting': 'nope'})
changed: [localhost] =&gt; (item={'dontyouhatepants': 'nope', 'name': 'app2', 'othersetting': 'yep', 'somesetting': 'yep'})

TASK: [debug var=item.stdout] *************************************************
ok: [localhost] =&gt; (item={'item': {'dontyouhatepants': 'yep', 'name': 'app1', 'othersetting': 'yep', 'somesetting': 'nope'}, u'delta': u'0:00:00.002124', u'cmd': u'/bin/echo &quot;app1&quot; ', u'end': u'2014-01-09 16:41:02.251091', u'stderr': u'', u'stdout': u'app1', 'invocation': {'module_name': 'shell', 'module_args': u'/bin/echo &quot;app1&quot;'}, u'changed': True, u'rc': 0, u'start': u'2014-01-09 16:41:02.248967'}) =&gt; {
    &quot;item&quot;: {
        &quot;changed&quot;: true,
        &quot;cmd&quot;: &quot;/bin/echo \&quot;app1\&quot; &quot;,
        &quot;delta&quot;: &quot;0:00:00.002124&quot;,
        &quot;end&quot;: &quot;2014-01-09 16:41:02.251091&quot;,
        &quot;invocation&quot;: {
            &quot;module_args&quot;: &quot;/bin/echo \&quot;app1\&quot;&quot;,
            &quot;module_name&quot;: &quot;shell&quot;
        },
        &quot;item&quot;: {
            &quot;dontyouhatepants&quot;: &quot;yep&quot;,
            &quot;name&quot;: &quot;app1&quot;,
            &quot;othersetting&quot;: &quot;yep&quot;,
            &quot;somesetting&quot;: &quot;nope&quot;
        },
        &quot;rc&quot;: 0,
        &quot;start&quot;: &quot;2014-01-09 16:41:02.248967&quot;,
        &quot;stderr&quot;: &quot;&quot;,
        &quot;stdout&quot;: &quot;app1&quot;
    },
    &quot;item.stdout&quot;: &quot;app1&quot;
}
ok: [localhost] =&gt; (item={'item': {'dontyouhatepants': 'nope', 'name': 'app2', 'othersetting': 'yep', 'somesetting': 'yep'}, u'delta': u'0:00:00.002419', u'cmd': u'/bin/echo &quot;app2&quot; ', u'end': u'2014-01-09 16:41:02.308687', u'stderr': u'', u'stdout': u'app2', 'invocation': {'module_name': 'shell', 'module_args': u'/bin/echo &quot;app2&quot;'}, u'changed': True, u'rc': 0, u'start': u'2014-01-09 16:41:02.306268'}) =&gt; {
    &quot;item&quot;: {
        &quot;changed&quot;: true,
        &quot;cmd&quot;: &quot;/bin/echo \&quot;app2\&quot; &quot;,
        &quot;delta&quot;: &quot;0:00:00.002419&quot;,
        &quot;end&quot;: &quot;2014-01-09 16:41:02.308687&quot;,
        &quot;invocation&quot;: {
            &quot;module_args&quot;: &quot;/bin/echo \&quot;app2\&quot;&quot;,
            &quot;module_name&quot;: &quot;shell&quot;
        },
        &quot;item&quot;: {
            &quot;dontyouhatepants&quot;: &quot;nope&quot;,
            &quot;name&quot;: &quot;app2&quot;,
            &quot;othersetting&quot;: &quot;yep&quot;,
            &quot;somesetting&quot;: &quot;yep&quot;
        },
        &quot;rc&quot;: 0,
        &quot;start&quot;: &quot;2014-01-09 16:41:02.306268&quot;,
        &quot;stderr&quot;: &quot;&quot;,
        &quot;stdout&quot;: &quot;app2&quot;
    },
    &quot;item.stdout&quot;: &quot;app2&quot;
}

PLAY RECAP ********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">
---

- hosts: localhost
  vars:
    myapp:
      - name: app1
        somesetting: nope
        othersetting: yep
        dontyouhatepants: yep
      - name: app2
        somesetting: yep
        othersetting: yep
        dontyouhatepants: nope
  tasks:
  - name: just an echo
    shell: /bin/echo "{{ item.name }}"
    with_items: myapp
    register: echo
  - debug: var=item.stdout
    with_items: echo.results



$ ansible-playbook -i inv/TEST test.yml

PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [just an echo] **********************************************************
changed: [localhost] =&gt; (item={'dontyouhatepants': 'yep', 'name': 'app1', 'othersetting': 'yep', 'somesetting': 'nope'})
changed: [localhost] =&gt; (item={'dontyouhatepants': 'nope', 'name': 'app2', 'othersetting': 'yep', 'somesetting': 'yep'})

TASK: [debug var=item.stdout] *************************************************
ok: [localhost] =&gt; (item={'item': {'dontyouhatepants': 'yep', 'name': 'app1', 'othersetting': 'yep', 'somesetting': 'nope'}, u'delta': u'0:00:00.002124', u'cmd': u'/bin/echo "app1" ', u'end': u'2014-01-09 16:41:02.251091', u'stderr': u'', u'stdout': u'app1', 'invocation': {'module_name': 'shell', 'module_args': u'/bin/echo "app1"'}, u'changed': True, u'rc': 0, u'start': u'2014-01-09 16:41:02.248967'}) =&gt; {
    "item": {
        "changed": true,
        "cmd": "/bin/echo \"app1\" ",
        "delta": "0:00:00.002124",
        "end": "2014-01-09 16:41:02.251091",
        "invocation": {
            "module_args": "/bin/echo \"app1\"",
            "module_name": "shell"
        },
        "item": {
            "dontyouhatepants": "yep",
            "name": "app1",
            "othersetting": "yep",
            "somesetting": "nope"
        },
        "rc": 0,
        "start": "2014-01-09 16:41:02.248967",
        "stderr": "",
        "stdout": "app1"
    },
    "item.stdout": "app1"
}
ok: [localhost] =&gt; (item={'item': {'dontyouhatepants': 'nope', 'name': 'app2', 'othersetting': 'yep', 'somesetting': 'yep'}, u'delta': u'0:00:00.002419', u'cmd': u'/bin/echo "app2" ', u'end': u'2014-01-09 16:41:02.308687', u'stderr': u'', u'stdout': u'app2', 'invocation': {'module_name': 'shell', 'module_args': u'/bin/echo "app2"'}, u'changed': True, u'rc': 0, u'start': u'2014-01-09 16:41:02.306268'}) =&gt; {
    "item": {
        "changed": true,
        "cmd": "/bin/echo \"app2\" ",
        "delta": "0:00:00.002419",
        "end": "2014-01-09 16:41:02.308687",
        "invocation": {
            "module_args": "/bin/echo \"app2\"",
            "module_name": "shell"
        },
        "item": {
            "dontyouhatepants": "nope",
            "name": "app2",
            "othersetting": "yep",
            "somesetting": "yep"
        },
        "rc": 0,
        "start": "2014-01-09 16:41:02.306268",
        "stderr": "",
        "stdout": "app2"
    },
    "item.stdout": "app2"
}

PLAY RECAP ********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0
</code></pre></div>
<p dir="auto">I currently have a single dynamic inventory for EC2 which lists hosts across several VPCs, inside those VPCs the hosts are assigned different roles which are mapped to ansible groups.<br>
However the <code class="notranslate">group_vars</code> folder support only one level, so if I have the same role present in 2 VPCs, I cannot assign different variables to hosts with the same role in different VPCs.</p>
<p dir="auto">I would like to have a structure like that:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=".
|-- ec2.py
`-- group_vars
    |-- management
    |   |-- all
    |   |-- bastion
    |   |-- elasticsearch
    |   `-- logstash
    |-- production
    |   |-- all
    |   |-- elasticsearch
    |   `-- web
    `-- staging
        |-- all
        |-- elasticsearch
        `-- web"><pre class="notranslate"><code class="notranslate">.
|-- ec2.py
`-- group_vars
    |-- management
    |   |-- all
    |   |-- bastion
    |   |-- elasticsearch
    |   `-- logstash
    |-- production
    |   |-- all
    |   |-- elasticsearch
    |   `-- web
    `-- staging
        |-- all
        |-- elasticsearch
        `-- web
</code></pre></div>
<p dir="auto">Where I would have:</p>
<ul dir="auto">
<li>3 groups for the VPCs. i.e. <code class="notranslate">management</code>, <code class="notranslate">production</code>, <code class="notranslate">staging</code>.</li>
<li>each of the VPC groups would have several groups. i.e. <code class="notranslate">elasticsearch</code>, <code class="notranslate">web</code>.</li>
</ul>
<p dir="auto">To allow several roles with the same names in different VPCs, they could be prefixed by their parent name in the inventory.<br>
<code class="notranslate">production</code> would have the following children <code class="notranslate">production-elasticsearch</code>, <code class="notranslate">production-web</code>.</p>
<p dir="auto">This subject has already be discussed in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="103851011" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/12156" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/12156/hovercard" href="https://github.com/ansible/ansible/issues/12156">#12156</a>, but the ticket was closed saying it's possible to do it using <code class="notranslate">a combination of inventory scripts and/or group_vars and host_vars</code> or by <code class="notranslate">implementing something like this as a plugin</code>.</p>
<p dir="auto">It's not possible to implement it with <code class="notranslate">a combination of inventory scripts and/or group_vars and host_vars</code> in the current state.<br>
And while a vars plugin seems the most adapted way if you need a workaround, it involves copying most of the code already present in ansible.</p>
<p dir="auto">Should I re-implement <a href="https://github.com/ansible/ansible/blob/63fbc1a76401ff8a74bcab3d1a8792f27a679185/lib/ansible/inventory/__init__.py#L800-L850"><code class="notranslate">_get_hostgroup_vars</code></a> in a plugin, or is there a better solution?</p>