Site icon installvirtual

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. 

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

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.

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.

Exit mobile version