# add\_host/group\_by how to do sub-groups

**URL:** <https://forum.ansible.com/t/add-host-group-by-how-to-do-sub-groups/33349>\
**Category:** Ansible Project\
**Created:** [July 8, 2020, 8:02pm UTC](https://forum.ansible.com/t/add-host-group-by-how-to-do-sub-groups/33349 "2020-07-08T20:02:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Kiick](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@Chris\_Kiick](https://forum.ansible.com/u/Chris_Kiick)\
**Post date:** [July 8, 2020, 8:02pm UTC](https://forum.ansible.com/t/add-host-group-by-how-to-do-sub-groups/33349/1 "2020-07-08T20:02:10Z")

</div>

Hi,

I’m exploring the use of add\_host instead of a rather convoluted dynamic inventory setup. I can create the groups for each host, either by specifying groups in add\_host, or using group\_by. However, these only create flat, first-level groups. Now I need to have a group hierarchy (group of groups). Some of the group names are created dynamically, so I can’t pre-load the inventory with the group organization.

How can a group of groups be created in the same way as group\_by creates groups?  
Put another way: how do I add a group to a group inside a playbook?

Thanks,
