'Ansible tower API: pass inventory for a job in a POST payload

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.



Solution 1:[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
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeff