# How to import inventory files from Ansible

**URL:** <https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655>\
**Category:** AWX Project\
**Tags:** awx, aws\
**Created:** [September 26, 2018, 11:42am UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655 "2018-09-26T11:42:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![GXW](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@GXW](https://forum.ansible.com/u/GXW)\
**Post date:** [September 26, 2018, 11:42am UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/1 "2018-09-26T11:42:48Z")

</div>

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/](https://copr.fedorainfracloud.org/coprs/mrmeee/awx/)

Regards,

GXW

---

<div class="post-metadata">

**Author:** ![Sujith\_A\_R](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@Sujith\_A\_R](https://forum.ansible.com/u/Sujith_A_R)\
**Post date:** [September 26, 2018, 12:05pm UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/2 "2018-09-26T12:05:39Z")

</div>

Importing inventories can be done through custom inventory script. I have seen a webinar from [https://www.ansible.com/resources/videos](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

---

<div class="post-metadata">

**Author:** ![Martin\_Juhl](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@Martin\_Juhl](https://forum.ansible.com/u/Martin_Juhl)\
**Post date:** [September 26, 2018, 12:08pm UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/3 "2018-09-26T12:08:31Z")

</div>

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](https://github.com/ansible/awx.git) | [https://github.com/ansible/awx.git](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

---

<div class="post-metadata">

**Author:** ![matburt](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/matburt/32/3612_2.png) [@matburt](https://forum.ansible.com/u/matburt)\
**Post date:** [September 26, 2018, 6:42pm UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/4 "2018-09-26T18:42:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GXW](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@GXW](https://forum.ansible.com/u/GXW)\
**Post date:** [September 28, 2018, 12:00pm UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/5 "2018-09-28T12:00:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rpetrell](https://avatars.discourse-cdn.com/v4/letter/r/b4bc9f/32.png) [@rpetrell](https://forum.ansible.com/u/rpetrell)\
**Post date:** [September 28, 2018, 12:13pm UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/6 "2018-09-28T12:13:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AlanCoding](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alancoding/32/301_2.png) [@AlanCoding](https://forum.ansible.com/u/AlanCoding)\
**Post date:** [September 28, 2018, 1:07pm UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/7 "2018-09-28T13:07:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Darkhan](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Darkhan](https://forum.ansible.com/u/Darkhan)\
**Post date:** [October 9, 2018, 3:53pm UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/8 "2018-10-09T15:53:55Z")

</div>

[https://docs.ansible.com/ansible-tower/latest/html/administration/tipsandtricks.html](https://docs.ansible.com/ansible-tower/latest/html/administration/tipsandtricks.html)

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.

---

<div class="post-metadata">

**Author:** ![Sanjeev\_Rana](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@Sanjeev\_Rana](https://forum.ansible.com/u/Sanjeev_Rana)\
**Post date:** [February 27, 2019, 1:21am UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/9 "2019-02-27T01:21:06Z")

</div>

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]#

1. 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]#

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

---

<div class="post-metadata">

**Author:** ![dmakovey](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dmakovey](https://forum.ansible.com/u/dmakovey)\
**Post date:** [February 27, 2019, 7:43pm UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/10 "2019-02-27T19:43:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Darkhan](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Darkhan](https://forum.ansible.com/u/Darkhan)\
**Post date:** [February 28, 2019, 9:13am UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/11 "2019-02-28T09:13:23Z")

</div>

This approach does not import variables though, which is really strange.

---

<div class="post-metadata">

**Author:** ![Gregory\_QUISTREBERT](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@Gregory\_QUISTREBERT](https://forum.ansible.com/u/Gregory_QUISTREBERT)\
**Post date:** [July 10, 2019, 10:47am UTC](https://forum.ansible.com/t/how-to-import-inventory-files-from-ansible/28655/12 "2019-07-10T10:47:07Z")

</div>

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.
