How to import inventory files from Ansible

4,089 views
Skip to first unread message

GXW

unread,
Sep 26, 2018, 7:42:48 AM9/26/18
to AWX Project

Hi,

 

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.

 

Can anyone tell me how to do this?  I am using AWX v1.0.2 which I built from this repo: https://copr.fedorainfracloud.org/coprs/mrmeee/awx/

 

Regards,

GXW

Sujith A R

unread,
Sep 26, 2018, 8:05:51 AM9/26/18
to GXW, AWX Project
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 

--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project...@googlegroups.com.
To post to this group, send email to awx-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/awx-project/0bba55db-df73-4f1b-867f-8908b6a11362%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Juhl

unread,
Sep 26, 2018, 8:08:33 AM9/26/18
to AWX Project

Hi


Has versioning or the way you are tagging version changed after 1.0.8??

mj@falcon:/Download$ git clone https://github.com/ansible/awx.git
Cloning into 'awx'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 179555 (delta 0), reused 1 (delta 0), pack-reused 179548
Receiving objects: 100% (179555/179555), 201.52 MiB | 6.75 MiB/s, done.
mj@falcon:
/Download/awx$ git describe --long
1.0.8-14-g8a66213db
mj@falcon:~/Download/awx$ git describe --long --first-parent
1.0.7-9-g8a66213db

When building the lastest source, the resulting tar.gz is named awx-1.0.7.9.tar.gz

-bash-4.2$ git describe --long
1.0.8-14-g8a66213db
-bash-4.2$ ls -la dist/
total 10652
drwxr-xr-x. 2 root root 32 Sep 26 11:35 .
drwxr-xr-x. 14 awx awx 4096 Sep 26 11:35 ..
-rw-r--r--. 1 root root 10900105 Sep 26 11:35 awx-1.0.7.9.tar.gz

In the makefile this is used:

VERSION=$(shell git describe --long --first-parent)
VERSION3=$(shell git describe --long --first-parent | sed 's/-g.//')
VERSION3DOT=$(shell git describe --long --first-parent | sed 's/-g.
//' | sed 's/-/./')
RELEASE_VERSION=$(shell git describe --long --first-parent | sed 's@([0-9.]{1,}).*@\1@')

Which results in the 1.0.7.9 version tag..


/Martin

Matthew Jones

unread,
Sep 26, 2018, 2:42:40 PM9/26/18
to bead...@gmail.com, grantwa...@gmail.com, AWX Project
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.

You don't have to write a script for this.


For more options, visit https://groups.google.com/d/optout.


--
Matt Jones
Principal Software Engineer
Ansible Tower

GXW

unread,
Sep 28, 2018, 8:00:13 AM9/28/18
to AWX Project
Hi Matt - sounded like a good plan but when I tried that I just got this error:

ERROR!
source_project: Cannot use manual project for SCM-based inventory.
Any ideas what I might be doing wrong?
P.S. I have re-installed as v1.0.8 with docker now.



Ryan Petrello

unread,
Sep 28, 2018, 8:13:49 AM9/28/18
to AWX Project
Hey GXW,

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).

Alan Rominger

unread,
Sep 28, 2018, 9:07:14 AM9/28/18
to Ryan Petrello, AWX Project
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.

Alan
github: AlanCoding


--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project...@googlegroups.com.
To post to this group, send email to awx-p...@googlegroups.com.

Adrian Sebastian Dutu

unread,
Oct 9, 2018, 11:53:56 AM10/9/18
to AWX Project
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.

Sanjeev Rana

unread,
Feb 26, 2019, 8:21:07 PM2/26/19
to AWX Project
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 .

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
[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

Cheers
Sanjeev Rana

Dmitry Makovey

unread,
Feb 27, 2019, 2:43:06 PM2/27/19
to AWX Project
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
> <https://copr.fedorainfracloud.org/coprs/mrmeee/awx/>
>
>  
>
> Regards,
>
> GXW
>
> --
> You received this message because you are subscribed to the Google
> Groups "AWX Project" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to awx-project...@googlegroups.com
> <mailto:awx-project...@googlegroups.com>.
> To post to this group, send email to awx-p...@googlegroups.com
> <mailto:awx-p...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/awx-project/9e02f67c-282e-4a13-a60f-afd36d523552%40googlegroups.com
> <https://groups.google.com/d/msgid/awx-project/9e02f67c-282e-4a13-a60f-afd36d523552%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
Sr System and DevOps Engineer SoM IRT

signature.asc

Adrian Sebastian Dutu

unread,
Feb 28, 2019, 4:13:24 AM2/28/19
to AWX Project
This approach does not import variables though, which is really strange.

Grégory QUISTREBERT

unread,
Jul 10, 2019, 6:47:07 AM7/10/19
to AWX Project
Hello Thanks,

Wich format and extension for the inventory file?

Host1 ansible_host=1.2.3.5
host2 ansible_host=5.6.7.8


Thanks a lot.
Reply all
Reply to author
Forward
0 new messages