I’ve been using Ansible for a couple of years now and have an inventory file with around 100 VMs in it which I manage.
I have just started to look at AWX so that I can add users and delegate some of my playbooks to other folks in the Company.
How can I import a static Ansible inventory file into AWX? I had a quick look at the Inventory pages and can see how to add hosts manually one at a time, and I think there’s a way to run inventory scripts to pull the details in from AWS etc, but all I want to do is paste in the 100 lines of inventory from my Ansible hosts file.
Importing inventories can be done through custom inventory script. I have seen a webinar from https://www.ansible.com/resources/videos where the presenter importing inventories through a python script file which reads up the local inventory and import it
Alternatively to a custom script you can create an inventory that references a file in a project. So add the project that contains the file and then create a new inventory, pick the project+file in the settings by adding it as an inventory source.
Exactly what it says - AWX doesn’t support SCM-based inventory when using manually synced projects (it only works for projects that come from source control, like git or svn).
There’s an issue in the queue that asks for specifically this - SCM inventory that imports from a manual project.
I have hesitations about that. Firstly, in that case, calling it SCM inventory is not correct. At that point, it’s file-based inventory, not SCM based. We already have a feature for file-based inventory. You use it by running the awx-manage CLI command to import inventory. If the server allowed SCM inventory from manual projects, then it would be doing the same management command, just through the API. If you’re using manual projects, then you’re doing things outside of the standard API interface already. In terms of implementation, there are cases where we use the SCM revision for certain things related to SCM inventory. That’s not a reason we couldn’t do this, but it would require special consideration in several cases (because manual projects don’t have a revision per se), and I think the drawbacks may outweigh the benefits.
Instead, it’s probably better to point to the CLI use of the inventory import command, and we’ll address any issues that come up with that.
Section 25.18
You just need to make sure you have the correct directory structure and then run awx-manage inside the task container and it will import everything.
Here’s the steps to upload the static inventory to Ansible AWX/ tower .
If you are using docker to run the AWX then for using awx-manage command you have to connect the awx web container " docker exec -it awx_web /bin/bash " and then follow the below commands .
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
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.
another way (and the one I personally favor) is to add inventory from a
project (as in: inventory file from a git project).
Roughly steps to go through:
1. create a Git (or any supported version control system) repo that
contains your inventory (Gitlab, Github, Subversion...whatever
2. add that repo as a project to AWX. Sync it.
3. create new inventory
3a. go into sources
3b. create new source that points to project from (2)/inventory_file
you've got
4. profit