# inventory export to csv format from ansible tower

**URL:** <https://forum.ansible.com/t/inventory-export-to-csv-format-from-ansible-tower/34776>\
**Category:** AWX Project\
**Created:** [March 13, 2021, 4:15pm UTC](https://forum.ansible.com/t/inventory-export-to-csv-format-from-ansible-tower/34776 "2021-03-13T16:15:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kumaresan\_M](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@Kumaresan\_M](https://forum.ansible.com/u/Kumaresan_M)\
**Post date:** [March 13, 2021, 4:15pm UTC](https://forum.ansible.com/t/inventory-export-to-csv-format-from-ansible-tower/34776/1 "2021-03-13T16:15:08Z")

</div>

Hi All,

I am looking for way to export inventory and some hostvars(gathered as part of dynamic inventory) from ansible tower to csv format.Could someone help here?

Regards  
Kumar

---

<div class="post-metadata">

**Author:** ![ffirg](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ffirg/32/10029_2.png) [@ffirg](https://forum.ansible.com/u/ffirg)\
**Post date:** [March 15, 2021, 9:29pm UTC](https://forum.ansible.com/t/inventory-export-to-csv-format-from-ansible-tower/34776/2 "2021-03-15T21:29:49Z")

</div>

I can get you most of the way there, but I’m sure there’s a better way out there!

ansible-galaxy collection install awx.awx

Create or add this to your ansible.cfg:

[inventory]  
enable\_plugins = awx.awx.tower

Get an oauth token:

awx login [-k if not using valid SSL cert]

Create a tower\_inventory.yml file:

plugin: awx.awx.tower  
host: 192.168.138.177  
oauth\_token: ^^^from-awx-login-above  
verify\_ssl: false  
inventory\_id: 1

Change details as required and then run:

ansible-inventory -i ./tower\_inventory.yml --list --export -y --output file.txt

cat file.txt:

all:  
children:  
testgroup1:  
hosts:  
bar:  
abc: def  
remote\_tower\_enabled: ‘true’  
remote\_tower\_id: 3  
foo:  
remote\_tower\_enabled: ‘true’  
remote\_tower\_id: 2  
ungrouped:  
hosts:  
localhost:  
ansible\_connection: local  
ansible\_python\_interpreter: ‘{{ ansible\_playbook\_python }}’  
remote\_tower\_enabled: ‘true’  
remote\_tower\_id: 1

You’ll need to figure out how to load that into excel. You can probably parse with something like jq but will need to figure that out, as my jq foo isn’t that good!

Hope that helps.  
Phil.

---

<div class="post-metadata">

**Author:** ![Kumaresan\_M](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@Kumaresan\_M](https://forum.ansible.com/u/Kumaresan_M)\
**Post date:** [March 16, 2021, 5:13pm UTC](https://forum.ansible.com/t/inventory-export-to-csv-format-from-ansible-tower/34776/3 "2021-03-16T17:13:11Z")

</div>

Hi Phil,

Thanks for the update.

Regards  
Kumar
