2

I am unable to assign a host to group in ansible tower inventory using rest API's. Any one have worked on it please let me know the request with body.

Oomkar
  • 21
  • 1
  • 4

1 Answers1

1

I found a solution. For me, the problem was that I was searching in api/v2/inventories/{id}/groups/; turns out you actually have to look in api/v2/groups/{id}/hosts/.


Add host to inventory group

URI: {your host}/api/v2/groups/{id}/hosts/

Method: POST

Payload:

{
    "name": "{hostname}",
    "description": "",
    "enabled": true,
    "instance_id": "",
    "variables": ""
}

This will create a host in the specified group.


In AWX and Ansible Tower, you can navigate to the url in your browser, then you can scroll all the way down, and if you can do a POST, there'll be a form there that has the payload. You can fill it in and post it right there in the browser.

When you are at the inventory group in the normal GUI, you can find the id of the inventory group in the URL.

dwrolvink
  • 11
  • 1