How To Export Tower Inventory Host & Group List

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.

Hello,

This endpoint should help you : https://docs.ansible.com/ansible-tower/latest/html/towerapi/api_ref.html#/Inventories/Inventories_inventories_script_read

Regards.

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.

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.

Dana ponedjeljak, 10. kolovoza 2020. u 18:34:03 UTC+2 korisnik m.hay...@apogee-innovations.com napisao je: