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.
Has anyone done bulk imports with the API while adding variables: to hosts. I need to load a couple 100 hosts with multiple variables. I can only get one variable to load. I have this valid JSON that does not work when using the API. This is one way of the multiples attempts I have tried:
{
“inventory”: 11,
“hosts”: [
{
“name”: “abc0017”,
“variables”: [
“vm_name: Dev FM Core 2”,
“primary_ip_address: 10.10.100.53”,
“os_vmware_tools: Ubuntu Linux (64-bit)”,
“ansible_connection: ssh”,
“ansible_port: 99”
]
}
]
}
And I have been trying variations on this for a while with no success. Any ideas?? Thanks in advance!
Pdin
This assumes your project is in some SCM and AWX has connectivity to it.
I’ve personally used the Sourced from a Project method where you specify your inventory in an SCM (GitHub, GitLab etc.) and point it to the repository and AWX will handle registering all the hosts, groups and their variables for you.
The confusion comes from variables: needing to be a string containing json which, because it’s embedded within a json value, must be properly escaped. Apparently.