It talks about one could bulk add host as following:
Post to /api/v2/bulk/host_create
POST accepts inventory and hosts desired to create, responds with how many hosts created, and link to inventory
But I still can’t figure out what is the exact curl command to bulk add hosts.
Also does it mean I have to list all my 200 hosts out in the POST command? Will it accept filename with host list inside?
I guess now I need to figure out how to build the host list for 200 hosts.
Can POST accept filename with host name inside?
Also, I still want to know how to use cURL command line.
I tried this: #curl -k -X POST https://myansible.com/v2/bulk/host_create/
{“detail”:“Authentication credentials were not provided. To establish a login session, visit /api/login/.”}
So how to specify Authentication in cURL command for Ansible AWX?
This payload.json file content can also be used to do posts in a browser.
So now I just need to modify my host list file a little bit (add prefix and surffix to the hostname). Then I can use browser or curl command to add 200 hosts!
Are you able to use the awx.awx Collection, and run Ansible locally to push the changes to your AWX?
There’s a similar topic here where I show how to create an inventory. You could then use awx.awx.host module to create the hosts in the inventories that you created.
How can I add multiple hosts with “Description”, “Inventory” and “Variables” of each host using /api/v2/… other any other method?
I tried this template it didn’t work:
{
“name”: “host1”,
“description”: “This is a test host”,
“inventory”: 1,
“enabled”: true,
“variables”: “—\nfavcolor: blue”
}
Also, I have the same problem with adding multiple job template. I’d appreciate it if someone could help me please.
Hello @djyasin
Sorry for my late reply. Unfortunately I’ve faced a problem on my awx server and I can’t test it now. It may take a couple of days to resolve the problem. I’ll give it a go as soon as I can fix the server issue and will post the result here.
Thank you
To bulk add hosts in Ansible AWX via the API, you can use the /api/v2/bulk/host_create/ endpoint with a properly formatted JSON payload. For authentication, include -u admin:myPassword in your cURL command. If you have a large list of hosts, prepare a JSON file with the inventory ID and host details, and then use the --data @payload.json option with cURL. This method is efficient for managing numerous hosts, much like handling multiple shipments with a tool like TraceShipments.
Can someone please explain to me what the point of AWX is?
It’s meant to be a GUI for Ansible, right?
But you can’t use the GUI to import a simple inventory file.
Instead, we’re expected to post json to an API endpoint.
What a disgrace.
The whole thing is bloated and hard. The only thing it brings to the table over using bash scripts is splicing, and that’s achievable yourself. If i need four Execution Node, then I could use four servers with podman.