Site icon UnixArena

AWX / Ansible Tower – Inventory & Bulk Hosts Import

AWX Tower - Inventory

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 ” + ”  .

Creating New inventory AW

3.  Once the new inventory is saved, click on “HOSTS” tab and click “+” to add new hosts.

Adding a New Host in AWX/Tower Inventory

4. Enter the host details and description.  You could also add host variable in the bottom of the table.

Enter the host detail – AWX/ Tower

5.  Navigate back to the Inventories tab.

List of inventory – AWX / Tower

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.

Hosts Added in AWX’s inventory

 

We have successfully added multiple ansible clients in a single shot using “awx-manage” command.

Exit mobile version