# Can group\_by add hosts to an existing group?

**URL:** <https://forum.ansible.com/t/can-group-by-add-hosts-to-an-existing-group/14297>\
**Category:** Ansible Project\
**Created:** [January 8, 2014, 6:31pm UTC](https://forum.ansible.com/t/can-group-by-add-hosts-to-an-existing-group/14297 "2014-01-08T18:31:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Casey](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mark\_Casey](https://forum.ansible.com/u/Mark_Casey)\
**Post date:** [January 8, 2014, 6:31pm UTC](https://forum.ansible.com/t/can-group-by-add-hosts-to-an-existing-group/14297/1 "2014-01-08T18:31:35Z")

</div>

If you use group\_by but the resulting group name already exists in your inventory, what happens? I’d assume the hosts that matched the group\_by and weren’t already in the group just get added to the group?

If necessary I don’t mind setting up a few VMs and testing it but I thought I’d see if anyone knew off the top of their head.

Thank you,  
Mark

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [January 8, 2014, 7:01pm UTC](https://forum.ansible.com/t/can-group-by-add-hosts-to-an-existing-group/14297/2 "2014-01-08T19:01:08Z")

</div>

The logic in question is here: [https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/action\_plugins/group\_by.py#L90-L92](https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/action_plugins/group_by.py#L90-L92)

“I’d assume the hosts that matched the group\_by and weren’t already in the group just get added to the group?”

More like: “the group is added to the host” based on the code

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [January 8, 2014, 7:02pm UTC](https://forum.ansible.com/t/can-group-by-add-hosts-to-an-existing-group/14297/3 "2014-01-08T19:02:57Z")

</div>

err, ignore that last sentence, you were correct. I’m cross-eyed from looking at code all day

---

<div class="post-metadata">

**Author:** ![Mark\_Casey](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mark\_Casey](https://forum.ansible.com/u/Mark_Casey)\
**Post date:** [January 8, 2014, 8:14pm UTC](https://forum.ansible.com/t/can-group-by-add-hosts-to-an-existing-group/14297/4 "2014-01-08T20:14:42Z")

</div>

No worries. Thanks for finding that; I’ll have to get more familiar with the source.
