Question how to add created Hosts to Groups with Playbook.

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

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

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

Try using the preserve_existing_hosts parameter https://docs.ansible.com/ansible/latest/collections/awx/awx/group_module.html#parameter-preserve_existing_hosts

-John