# Is it possible to get the child groups of a given group in an expression

**URL:** <https://forum.ansible.com/t/is-it-possible-to-get-the-child-groups-of-a-given-group-in-an-expression/21931>\
**Category:** Ansible Project\
**Created:** [July 6, 2016, 10:02am UTC](https://forum.ansible.com/t/is-it-possible-to-get-the-child-groups-of-a-given-group-in-an-expression/21931 "2016-07-06T10:02:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@Mark\_Davis](https://forum.ansible.com/u/Mark_Davis)\
**Post date:** [July 6, 2016, 10:02am UTC](https://forum.ansible.com/t/is-it-possible-to-get-the-child-groups-of-a-given-group-in-an-expression/21931/1 "2016-07-06T10:02:40Z")

</div>

From a quick look at [https://github.com/ansible/ansible/blob/devel/lib/ansible/inventory/group.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/inventory/group.py) I think the answer is “no” as child\_groups doesn’t have a getter, but just in case…

Is it possible to get the list of child groups of a given group?

The use case here would be for a jinja template (pseudo):

`{% for my_group in groups['my-cluster'] %} { "name" : "{{ my_group.name }}", "hosts" : [{% for host in groups['{{ my_group.name }}] %}{"fqdn" : "{{ hostvars[host]['inventory_hostname'] }}"}{% if not loop.last %},{% endif %} {% endfor %}] }{% if not loop.last %},{% endif %} {% endfor %}`

There is an easy workaround which involves some duplication, but just curious if there’s a way to get the above to work.
