'How to trigger an Ansible Tower Job template from Github branch commit?
How can I trigger a job in Ansible Tower using its API on a Github branch commit?
I could use a Github webhook but when triggered by a push it occurs regardless of branch. I'm wondering if the webhook payload could provide info but I m not sure how to utilize it within the job. Am I on the right track or is there a better approach?
Thanks.
Solution 1:[1]
You could use a pipeline using GitHub actions and conditionals. For example:
on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- main
pull_request:
branches:
- main
Taken from here.
Solution 2:[2]
The webhook payload does provide information. Check the extra variables in the output of a job triggered by a webhook. More information about how the payload is exposed as an extra variable can be found here:
https://docs.ansible.com/automation-controller/4.1.0/html/userguide/webhooks.html#payload-output
You can use the values of the payload variables to perform conditional actions with Ansible.
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 | Rafael de Bem |
Solution 2 |