inventory export to csv format from ansible tower

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

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.

Hi Phil,

Thanks for the update.

Regards
Kumar