Hi all,
I hope someone can help me here.
I need to do a one-off import of 500 hosts into the AWX inventory. When I tested this back in March, I was able to get a bash shell on the awx-web container going and run the command:
awx-manage inventory_import --inventory-name --source hosts
This would take my hosts file and all the related host_vars files and put them in the inventory nicely. After that, I was going to manually maintain the inventory since it doesn’t change a lot.
I come to try to deploy this 9 months later, and it fails - complains that podman isn’t in the container. I see from this issue that apparently the containers aren’t supposed to have pod man in them.
Can anyone give me a way of importing a large number of hosts into the inventory? I thought aww-manage was the way to do this, and Tower documentation still refers to my method that worked back in March.
Many thanks,
Andrew
What about using the awx.awx collection? Specifically the awx.awx.inventory(1) module to create the inventory and then awx.awx.host(2) module to pull the hosts into the inventory. If the hosts file is parsable you should be able to read it in and do a loop to make this happen in a playbook.
(1) https://docs.ansible.com/ansible/latest/collections/awx/awx/inventory_module.html#ansible-collections-awx-awx-inventory-module
(2) https://docs.ansible.com/ansible/latest/collections/awx/awx/host_module.html#ansible-collections-awx-awx-host-module
Thanks for the ideas on that. I had a similar one while I was eating my cornflakes this morning. Sometimes a break is as good as a rest. In the end, a colleague and I worked on a python script that put a JSON structure into the inventory via the API:
def create_host(
hostname: str, mgmt_ip: str, model: str, serial: str, ipsec_endpoint: str
):
data = {
“hostname”: hostname,
“management_ip”: mgmt_ip,
“model”: model,
“serial”: serial,
“ipsec_endpoint”: ipsec_endpoint,
}
result=requests.post(“https://awx.test.com/api/v2/inventories/2/hosts/",headers={“Authorization”:"Bearer ”},json={“name”:hostname,“variables”:json.dumps(data)},verify=False)
Seems to work. Just makes me wonder why they’ve made the previous method using aww-manage inoperative.
Thanks again for taking time to reply.
Andrew