Ansible - Launch a Job Template using the Ansible Tower API
by
Jeremy Canfield |
Updated: September 23 2024
| Ansible articles
Let's say you have a Job Template named foo job in Ansible Tower and you want to launch this Job Template using the Ansible Tower API.
Let's say this is URL for your Job Template in Ansible Tower.
https://tower.example.com/#/templates/job_template/12345/details
In this scenario, the base URL to submit a request such as a GET or POST request to the Job Template would be.
https://tower.example.com/api/v2/job_templates/
For example, here is how you could submit a POST request to Launch the Job Template using curl.
curl \
--request POST \
--header "Authorization: Bearer abc123" \
--url https://tower.example.com/api/v2/job_templates/12345/launch
Often, you are going to want to pass in additional values, such as Extra Variables and perhaps limit too.
curl \
--request POST \
--header "Authorization: Bearer abc123" \
--header "Content-Type: application/json" \
--url https://tower.example.com/api/v2/job_templates/12345/launch \
--data '{"extra_vars": {"foo": "Hello","bar":"World",},"limit": "dlhowas-1-0001.thrivent.com"}'
You may need to toggle on the "Prompt on Launch" option for Extra Variable so that the ask_variables_on_launch is set to True.
Did you find this article helpful?
If so, consider buying me a coffee over at