0

I need to retrieve the inventory_id for a given project (project_dev is the project name) from ansible tower using curl command

curl -X GET -s -k -u "user:password" -vvv  -H 'Content-Type:application/json' -d '{"organization": 1,"name": "project-dev"}' https://ansibletower.com/api/v2/inventories/"
user312307
  • 153
  • 6
  • 21
  • What's wrong with [tower-cli](https://github.com/ansible/tower-cli)? See [Inventory](https://tower-cli.readthedocs.io/en/latest/api_ref/resources/inventory.html). – Vladimir Botka Jul 04 '19 at 18:40
  • I am using shell script and need the inventory_id retrieved from ansible tower via automation – user312307 Jul 04 '19 at 18:46

1 Answers1

0

Q: I need to retrieve the inventory_id from ansible tower.

A: Use tower-cli

Usage: tower-cli inventory get [OPTIONS] [ID]

Q: How to add special character password to tower-cli config?

A: Use tower_cli.cfg

$ cat $HOME/.tower_cli.cfg 
[general]
host = http://srv.example.com
username = admin
password = password
verify_ssl = no
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
  • How to add special character password to tower-cli config? – user312307 Jul 04 '19 at 19:01
  • No, I am not asking you to read the doc, my password contains special character and I was unable to add it to tower-cli config. I have figured out how to do that now. – user312307 Jul 04 '19 at 19:24
  • When I try ```tower-cli inventory get ID```, I get below error and I was also trying to understand how can I pass project_name ```Error: The requested object could not be found.``` – user312307 Jul 04 '19 at 19:31
  • ```tower-cli inventory get -n project_dev | sed -e '1,3d'| sed -e '2d'| awk '/^[0-9]/ {print $1}'``` This command retrieves the inventory_id for a given project name using tower-cli – user312307 Jul 05 '19 at 14:39