# Question how to add created Hosts to Groups with Playbook.

**URL:** <https://forum.ansible.com/t/question-how-to-add-created-hosts-to-groups-with-playbook/36660>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [May 25, 2022, 2:31pm UTC](https://forum.ansible.com/t/question-how-to-add-created-hosts-to-groups-with-playbook/36660 "2022-05-25T14:31:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Neufer](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Christopher\_Neufer](https://forum.ansible.com/u/Christopher_Neufer)\
**Post date:** [May 25, 2022, 2:31pm UTC](https://forum.ansible.com/t/question-how-to-add-created-hosts-to-groups-with-playbook/36660/1 "2022-05-25T14:31:21Z")

</div>

Hello together,  
i have a Problem and i cant figure it out by myselve.

With This Play i can add a Host to my AWX Inventory.

- name: Add Win host to Inventory:

name: “{{ host\_name }}”

tower\_host:

tower\_username:

tower\_password:

description: “{{ host\_desc }}”

inventory: “Windows\_Servers”

state: present

validate\_certs: False

This play works fine. But how i can add this host to a group that exist in the inventory Windows\_Servers ?

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![AWX\_Project](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@AWX\_Project](https://forum.ansible.com/u/AWX_Project)\
**Post date:** [May 25, 2022, 3:06pm UTC](https://forum.ansible.com/t/question-how-to-add-created-hosts-to-groups-with-playbook/36660/2 "2022-05-25T15:06:56Z")

</div>

The formatting is a little mixed up but it looks like you are using awx.awx.host module for this.  
To create and manage groups (including adding hosts to them), try looking at the awx.awx.group module.

-The AWX Team

---

<div class="post-metadata">

**Author:** ![Christopher\_Neufer](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Christopher\_Neufer](https://forum.ansible.com/u/Christopher_Neufer)\
**Post date:** [June 3, 2022, 12:09pm UTC](https://forum.ansible.com/t/question-how-to-add-created-hosts-to-groups-with-playbook/36660/3 "2022-06-03T12:09:29Z")

</div>

Tanks for your help!

It is working but now i have another Problem.  
Adding a new Host to a Group is deleting all existing Hosts in this group.  
How can i fix that ?

- name: Add tower group tower\_group:

name: win\_svr

inventory: “Windows\_Servers”

hosts: “{{ host\_name }}”

state: present

tower\_host:

tower\_username:

tower\_password:   
validate\_certs: False

Cheers  
Chris

---

<div class="post-metadata">

**Author:** ![AWX\_Project](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@AWX\_Project](https://forum.ansible.com/u/AWX_Project)\
**Post date:** [June 6, 2022, 9:44am UTC](https://forum.ansible.com/t/question-how-to-add-created-hosts-to-groups-with-playbook/36660/4 "2022-06-06T09:44:39Z")

</div>

Try using the `preserve_existing_hosts` parameter [https://docs.ansible.com/ansible/latest/collections/awx/awx/group\_module.html#parameter-preserve\_existing\_hosts](https://docs.ansible.com/ansible/latest/collections/awx/awx/group_module.html#parameter-preserve_existing_hosts)

-John
