3

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?

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
KrishnaR
  • 344
  • 4
  • 14
  • _and send it to Job on Ansible Tower which is waiting_ > Is this a good idea? Wouldn't it be a better solution to end your actual playbook there and have another playbook callable via a API template that would do the restart the said service (and actually the "Deny" bouton would just nothing)? – β.εηοιτ.βε Apr 29 '22 at 06:47

1 Answers1

1

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
W4hf
  • 715
  • 1
  • 5
  • 12
  • How can we capture the response (approved or denied) from slack and send it to Job on Ansible Tower which is waiting ? – KrishnaR Apr 24 '22 at 06:06
  • I think this is more of a Slack-related question than Ansible Tower. Start by looking through the Salck API documentation. Sorry I'm not a Slack expert :( – W4hf Apr 26 '22 at 14:04