1

does anyone know if it is possible to pass an inventory (the actual list of servers) in a POST's payload when launching a job on Ansible tower via the API?

Thanks Wojtek

I could not find any reference about it in the documentation. The only option I can think of now is using inventory plugins or add_host module and build the inventory leveraging the same logic that would be used in the external job calling API. However that will not necessarily mimic what I need as I need to exec multiple seperate jobs with inventory in each being nodes of the same cluster.

Marvin
  • 1,650
  • 4
  • 19
  • 41
wb84
  • 11
  • 2
  • Does [Ansible Tower REST API - Inventories](https://docs.ansible.com/ansible-tower/latest/html/towerapi/api_ref.html#/Inventories) is not what you are looking for? – U880D Mar 31 '22 at 11:53
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 01 '22 at 13:29

1 Answers1

1

From your questions it appears to me that you want pass an actual list of devices within inventory. You may pass the actual list of servers using the 'limit' parameter:

For example payload should be like:

{
  "extra_vars": {
 // your variables used in the playbook
    "xyz" : "abc"
  },
  "limit": ["server1", "server2", "server3"]
}

Tip -> you need enable 'ask_limit_on_launch' in job_template settings. Then only Ansible tower will only consider the 'limit' parameter.

To enable the 'ask_limit_on_launch' flag Refer this image (just click the checkbox to 'prompt on launch' for limit parameter in edit UI)

If you are still looking for inventory... enable flag 'ask_inventory_on_launch'. for that (just click the checkbox to 'prompt on launch' for inventory parameter) And payload would be like

{
  "extra_vars": {
 // your variables used in the playbook
    "xyz" : "abc"
  },
  "inventory_id": 5
}
Jeff
  • 3
  • 2
  • Refer the link for API doc https://docs.ansible.com/ansible-tower/latest/html/towerapi/api_ref.html#/Job_Templates/Job_Templates_job_templates_launch_create – Shriram Jadhav Apr 09 '22 at 02:11