# Unable to associate the hosts to a group when using API calls in ansible playbook

**URL:** <https://forum.ansible.com/t/unable-to-associate-the-hosts-to-a-group-when-using-api-calls-in-ansible-playbook/25935>\
**Category:** Ansible Project\
**Created:** [November 6, 2017, 8:55am UTC](https://forum.ansible.com/t/unable-to-associate-the-hosts-to-a-group-when-using-api-calls-in-ansible-playbook/25935 "2017-11-06T08:55:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alok\_Patra](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@Alok\_Patra](https://forum.ansible.com/u/Alok_Patra)\
**Post date:** [November 6, 2017, 8:55am UTC](https://forum.ansible.com/t/unable-to-associate-the-hosts-to-a-group-when-using-api-calls-in-ansible-playbook/25935/1 "2017-11-06T08:55:54Z")

</div>

I am able to create inventories, groups and hosts. However I am unable to associate the hosts to a group.

[http://docs.ansible.com/ansible-tower/latest/html/towerapi/host\_list.html](http://docs.ansible.com/ansible-tower/latest/html/towerapi/host_list.html)

The ansible documentation for creating hosts doesn’t mention how to link the hosts with a group

[http://docs.ansible.com/ansible-tower/latest/html/towerapi/group\_list.html](http://docs.ansible.com/ansible-tower/latest/html/towerapi/group_list.html)

The documentation for creating a group also doesn’t specify any variables to specify hosts under it.

main.yml

```auto
- name: Create a group in Ansible Tower Inventory
  uri:
    url: https:// ***tower_ip*** /api/v2/groups/
    method: POST
    user: admin
    password: password
    body: "{{ lookup('file','Inven4-Group2.json') }}"
    force_basic_auth: yes
    status_code: 201
    body_format: json
    validate_certs: False
  register: Inventory-creation-result

- name: Create a host in Ansible Tower Inventory
  uri:
    url: https:// ***tower_ip*** /api/v2/hosts/
    method: POST
    user: admin
    password: password
    body: "{{ lookup('file','Inven4-Group1-Host1.json') }}"
    force_basic_auth: yes
    status_code: 201
    body_format: json
    validate_certs: False
  register: Host-creation-result

```

Inven4-Group1-Host1.json

```auto
{"name": "Inven4-Group1-Host1", "inventory": 4}

```

Inven4-Group1.json

```auto
{"name": "Inven4-Group1", "inventory": 4}

```
