# Dynamic inventory, empty group with children

**URL:** <https://forum.ansible.com/t/dynamic-inventory-empty-group-with-children/15039>\
**Category:** Ansible Project\
**Created:** [April 17, 2014, 11:31am UTC](https://forum.ansible.com/t/dynamic-inventory-empty-group-with-children/15039 "2014-04-17T11:31:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dane](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@Dane](https://forum.ansible.com/u/Dane)\
**Post date:** [April 17, 2014, 11:31am UTC](https://forum.ansible.com/t/dynamic-inventory-empty-group-with-children/15039/1 "2014-04-17T11:31:00Z")

</div>

Hello list,

I’m working on a dynamic inventory script for our Ansible deployment. Mostly we’re going to be dealing with clusters of machines, so from our side we’re grouping hosts into the cluster they’ll be in and each host of a cluster has the same set of Ansible variables pushed to it.

These groups of clusters then need to be assigned to the type of cluster they are in Ansible so we run the correct playbook against them - lets say we have clusters of layer 4 and layer 7 loadbalancers and some HA Varnish boxes, so we’d have three Ansible groups “l4”, “l7” and “varnish” and these would get assigned appropriate Ansible roles. Since each cluster should get the same set of variables, it made sense to me that these should go into group\_vars, then each host may or may not have individual host\_vars.

This is what my dynamic inventory script is currently spitting out (excuse the random names, I auto-generated the test data from /usr/share/dict/words!): [http://p.rig.gr/view/6472db0c](http://p.rig.gr/view/6472db0c)

You can see that I’ve got the cluster groups at the top level, but then I’m trying to group these within Ansible:

```auto
    "varnish": {
        "children": [
            "turbinate80",
            "roofgarden90"
        ]
    }

```

```auto

```

```auto
This way, I know that the clusters "turbinate80" and "roofgarden90" (which both contain two hosts each) are Varnish boxes and should run the Varnish role. The hosts inside those groups will get their associated group_vars, then pull in any host vars from the _meta bit (currently empty).

```

```auto

```

```auto
What actually happens is that the 'empty' varnish group (and l4/l7) is being picked up as a host in it's own right, rather than as just a group:

```

```auto

```

> ```auto
> (env)[dane@shrike ...nsible/spire]% ansible all -i spire.py --list-hosts
> 
> ```
> 
> ```auto
> 192.168.0.131
> 
> ```
> 
> ```auto
> 192.168.0.132
> 
> ```
> 
> ```auto
> 192.168.0.115
> 
> ```
> 
> ```auto
> 192.168.0.116
> 
> ```
> 
> ```auto
> 192.168.0.130
> 
> ```
> 
> ```auto
> 192.168.0.129
> 
> ```
> 
> ```auto
> l7
> 
> ```
> 
> ```auto
> 192.168.0.15
> 
> ```
> 
> ```auto
> 192.168.0.16
> 
> ```
> 
> ```auto
> 192.168.0.25
> 
> ```
> 
> ```auto
> 192.168.0.26
> 
> ```
> 
> ```auto
> l4
> 
> ```
> 
> ```auto
> webcel
> 
> ```

> (env)[dane@shrike …nsible/spire]% ansible l4 -i spire.py --list-hosts
> 
> l4
> 
> 192.168.0.131
> 
> 192.168.0.132

Now, I can move stuff around to make this work (getting rid of group\_vars and dumping everything under \_meta, even though this will duplicate some stuff), but I’m wondering if there’s a way to do what I’m after (group of groups, I guess) or if I’m just approaching this in the wrong way?

Thanks

Dane

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 17, 2014, 11:54am UTC](https://forum.ansible.com/t/dynamic-inventory-empty-group-with-children/15039/2 "2014-04-17T11:54:35Z")

</div>

I suspect the code is looking for a “hosts” entry in the JSON, and it’s not there. Can you try adding an empty “hosts” array in that group response?

---

<div class="post-metadata">

**Author:** ![Dane](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@Dane](https://forum.ansible.com/u/Dane)\
**Post date:** [April 17, 2014, 12:13pm UTC](https://forum.ansible.com/t/dynamic-inventory-empty-group-with-children/15039/3 "2014-04-17T12:13:01Z")

</div>

That was it! Seems to be working how I want it to now. Many thanks!

Dane
