These snippets will get you setup with sending slack messages in a jiffy from your ansible playbooks.
The Task
First we'll setup a simple wrapper task. Create a file called tasks/slack.yaml
. We'll use import_tasks
later to call this task.
- name: Send slack notification
slack:
token: "your/token/here..."
msg: "{{ message }}"
channel: "{{ channel }}"
username: "ansible"
color: "{{ color | default('good') }}"
link_names: 1
The Playbook
Simply add the following block to your existing playbook(s). Notice how we pass vars
to our task wrapper (above).
- name: Post-rollout
tasks:
- block:
- import_tasks: tasks/notifications/slack.yaml
vars:
channel: "#mychannel"
message: "Rollout finished! Please resume active monitoring!"
See also
https://docs.ansible.com/ansible/latest/modules/slack_module.html