How To Export Tower Inventory Host & Group List

2,992 views
Skip to first unread message

Marcus Hayhurst

unread,
Jul 27, 2020, 10:31:43 AM7/27/20
to AWX Project
Hello everyone,

Is there a way to export my Tower (3.7.0) Inventory?  I need to get a list of every host and it's corresponding group in a CSV (if possible).  I see this documentation but I do not see how I can get the information I need using the API calls.

ahmed

unread,
Jul 28, 2020, 10:08:06 AM7/28/20
to AWX Project

m.hay...@apogee-innovations.com

unread,
Aug 10, 2020, 12:34:03 PM8/10/20
to AWX Project
Thank you.  How would I make a GET request for only the "name" field which lists the hostnames in the API?  This works for my specific inventory: https://hostname/api/v2/inventories/4/hosts/?order_by=name  but returns all the fields.

Hrvoje Gašpar

unread,
Aug 11, 2020, 2:49:19 AM8/11/20
to AWX Project
Hey there m.hay

If you're using bash, you can use curl to submit an api request to tower, and then pipe it to jq in order to parse the response. Try something like this:

curl -k --user user:pass https://hostname/api/v2/inventories/4/hosts/ | jq '.results[] | .name, .summary_fields.groups.results[].name'

Just make sure to use your own username and password. Or, even better, set a bearer token if you know how to use one.

Reply all
Reply to author
Forward
0 new messages