AWX / Ansible Tower’s inventory is a key component to start the automation. Creating the inventory could be a lengthy process when you use the graphical user interface. AWX/Tower offers multiple methods to add the hosts into inventory. In this article, we will see that how to add the hosts in Ansible Tower/ AWX inventory using GUI and bulk import using the command line. The following method will guide you to add the ansible clients using AWX/Tower GUI method.
1. Login to Ansible Tower/ AWX with admin privileges.
2. Create a new inventory by navigating to they inventories tab. Click on ” + ” .
3. Once the new inventory is saved, click on “HOSTS” tab and click “+” to add new hosts.
4. Enter the host details and description. You could also add host variable in the bottom of the table.
5. Navigate back to the Inventories tab.
Add Multiple hosts in AWX/ Ansible Tower – Bulk Import
Ansible Tower / AWX offers utility called “awx-manage” to perform plenty of operations in CLI . One of the most important features of “awx-manage” is bulk hosts import. Using this utility, you could add N-number of ansible clients in few minutes.
1. Login to Ansible Tower’s host or AWX’s task container in interactive mode (Linux Host). Execute the following command to check the “awx-manage” version
[root@awx awx]# awx-manage --version 1.0.8.0 [root@awx awx]#
2. Create a file with the list of hosts which needs to be added into Ansible Tower/AWX’s inventory.
[root@awx awx]# cat hosts_add 192.168.3.152 192.168.3.153 192.168.3.154 192.168.3.155 192.168.3.156 192.168.3.157 192.168.3.158 192.168.3.159 [root@awx awx]#
3. Once the list is ready, identify the inventory name in which you need to add the hosts from AWX/Tower’s GUI. (Refer Step 5). In the example, I will be adding the prepared hosts into “Linux_UA_Hosts” inventory.
[root@awx awx]# awx-manage inventory_import --inventory-name Linux_UA_Hosts --source hosts_add 13.320 INFO Updating inventory 2: Linux_UA_Hosts 13.965 INFO Reading Ansible inventory source: /var/lib/awx/hosts_add 22.051 INFO Processing JSON output... 22.052 INFO Loaded 0 groups, 8 hosts 2018-11-26 17:03:32,529 DEBUG awx.main.models.inventory Going to update inventory computed fields 2018-11-26 17:03:32,705 DEBUG awx.main.models.inventory Finished updating inventory computed fields 22.581 INFO Inventory import completed for (Linux_UA_Hosts - 7) in 10.2s [root@awx awx]#
4. Go back to Tower’s/ AWX’s GUI to verify our work.
We have successfully added multiple ansible clients in a single shot using “awx-manage” command.
Javeed says
I have installed AWX via K3s AWX-operator and I am getting below error when I tried to add the inventory via Pod container.
bash-5.1$ awx-manage inventory_import –inventory-name npd-test-hosts –source /var/tmp/ansible_hosts
1.076 INFO Updating inventory 2: npd-test-hosts
2023-04-17 22:56:20,479 INFO [-] awx.analytics.job_lifecycle inventoryupdate-8 created
1.108 WARNING This command is not able to run on kubernetes-based deployment. This action should be done using the API.
bash-5.1$
ALEX says
you need to go under the user who installed awx , in the .awx directory , in my case root
A. cd
B. /root/.awx/awxcompose
C. docker exec -it awx_task bash
D. docker exec -it awx_task bash
bash-4.4# awx-manage –version
15.0.1
Fernando Kleiman says
Thank you! That was a good tip that worked for me!
stuck says
awx-manage command not found n the system… any way to solve it ?!
[root@ansiblemaster awx]# which awx-manage
/usr/bin/which: no awx-manage in (/sbin:/bin:/usr/sbin:/usr/bin)
amine says
is it possible to make the inventory sync ? that mean if i change in the file of the inventory ( add or remove nodes ) the inventory in the ansible tower change ?
Lingeswaran R says
I haven’t tried that.
Thank you.
Lingesh
Sanjeev Rana says
awx-manage: command not found
What package need to install ?