inventory export to csv format from ansible tower

1,474 views
Skip to first unread message

kumare...@gmail.com

unread,
Mar 13, 2021, 11:15:09 AM3/13/21
to AWX Project
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

phil.gr...@gmail.com

unread,
Mar 15, 2021, 5:29:49 PM3/15/21
to AWX Project
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.

kumare...@gmail.com

unread,
Mar 16, 2021, 1:13:11 PM3/16/21
to AWX Project
Hi Phil,

Thanks for the update.

Regards
Kumar 

Reply all
Reply to author
Forward
0 new messages