Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send Ansible Tower workflow template approval to Slack channel and recieve response from Slack channel?

I have a situation where the approval logic in Ansible Tower workflow template is working fine, Slack notifications are also working fine, but, I want to send approve and deny buttons to Slack and capture response from Slack channel to Ansible Tower workflow template.

I get the notifications like this:

The approval node "Proceed for L1" needs review. This node can be viewed at: https://ansibletower/#/workflows/668
The approval node "Proceed for L1" was approved. https://ansibletower/#/workflows/668

The approval node "Proceed for L1" needs review. This node can be viewed at: https://ansibletower/#/workflows/674
The approval node "Proceed for L1" was denied. https://ansibletower/#/workflows/674

But can we get the approval messages like this:

Slack Buttons

I tried a playbook to use Slack module but waiting for the response and receiving action response was the challenge

    - name: Post Message to Slack
      slack:
        token: "{{ slack_token }}"
        attachments:
          - title: Launched {{ tower_job_id }} and Restart Service
            text: "*Actions:*"
            actions:
            - type: button
              text: Approve
              style: primary
              url: https://anisbletower/#/templates/job_template/17
            - type: button
              text: Deny
              style: danger
              url: https://ansibletower/#/templates/job_template/15
            - type: button
              text: Check Job Log
              url: https://ansibletower/#/jobs/playbook/{{ tower_job_id }}
        channel: {{ slack_channel }}
        domain: "app.slack.com"
      delegate_to: localhost

How can we capture the response (approved or denied) from Slack and send it to the job on Ansible Tower which is waiting?

like image 419
KrishnaR Avatar asked Jan 25 '26 12:01

KrishnaR


1 Answers

Maybe after your task you can add a task that get the workflow status and move on only if the status is approved or denied, something like :

- name: get workflow status
  <some magic to get workflow_status, maybe uri module + tower api>
  until: workflow_status == approved or workflow_status == denied
  retries: 10
  delay: 10
like image 129
W4hf Avatar answered Jan 28 '26 18:01

W4hf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!