nordvpn

Notification on slack after completion of Ansible

Notification on slack after completion of Ansible

In this post I will show you how to configure slack notification from Ansible. There is a time when you want to get notified after the ansible playbook executed successfully or you want to check the services after the deployment. So, you can use slack incoming webhook notifications.

Read Also: How to install coinmon

You can use this https://api.slack.com/incoming-webhooks to setup incoming webhook notification. Click on incoming webhook notification to get started. Slack Notification from Ansible

Then on the next page you can select on which page you want to send the notification. See image below:

Slack Notification from Ansible

You might also like: Test shell script on circleci using shellcheck

After selecting the channel or user now its time to generate the token for incoming messages.

Slack Notification from Ansible

Ansible Playbook

After generating the token now its time to configure the Ansible playbook to send notifications to Slack. Here is my Ansible playbook to send the notification. In the playbook I checked the status of httpd services and it will send the status on slack channel.

---
- hosts: "{{ hosts }}"
- name: Status of Apache
    command: service httpd status
    register: output

- name: Send notification to Slack
    local_action:
     module: slack
     token: *****/******/*************
     channel: "#ansible"
     msg: "Status of apache on host {{ ansible_hostname }} is {{ output.stdout_lines }}"

It will send notification to ansible channel  on slack.

Please let me if you have any issue using this tutorial and if it is interesting for you please let me know.

Leave a Reply

Your email address will not be published.


*



The reCAPTCHA verification period has expired. Please reload the page.

48-Hour Flash Sale! Courses from just $10.99