From 1976a8d804bc1aaee7136baa76df5302bb353daf Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Fri, 2 Aug 2024 18:07:12 +0200 Subject: [PATCH] chore(slack): send messages using ansible --- knowledge base/slack.md | 2 ++ snippets/ansible/tasks.yml | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/knowledge base/slack.md b/knowledge base/slack.md index 8147190..178b6fd 100644 --- a/knowledge base/slack.md +++ b/knowledge base/slack.md @@ -60,6 +60,7 @@ Check out [slackmojis] for some common reactions. ## Further readings - [Website] +- [Posting messages using curl] ### Sources @@ -74,6 +75,7 @@ Check out [slackmojis] for some common reactions. +[posting messages using curl]: https://api.slack.com/tutorials/tracks/posting-messages-with-curl [website]: https://slack.com/ diff --git a/snippets/ansible/tasks.yml b/snippets/ansible/tasks.yml index 6de39b3..7ca3a34 100644 --- a/snippets/ansible/tasks.yml +++ b/snippets/ansible/tasks.yml @@ -131,6 +131,9 @@ - name: Remove elements from lists set_fact: list_without_items: "{{ dbs_list | difference(['template0','template1','postgres','rdsadmin']) }}" + - name: Get a random element + set_fact: + random_item: "{{ ['a','b','c'] | random }}" - name: Sort dict elements in list by attribute vars: snapshots: @@ -391,3 +394,27 @@ retries: 12 delay: 15 until: instance_check.instances[0].pending_modified_values.keys() | length > 0 + +- name: Send messages to Slack channels + vars: + slack_notification_hook_url: https://hooks.slack.com/services/AB01CD23EF4/ABCD0123E/aBcDefGh0123456789iJKLmn + block: + - name: Send plain messages + ansible.builtin.uri: + url: "{{ slack_notification_hook_url }}" + method: POST + body_format: json + body: + text: (╥╯ᗝ╰╥) task XYZ failed + - name: Send mrkdwn (Slack-specific markdown) text + # FIXME: still to be tested + ansible.builtin.uri: + url: "{{ slack_notification_hook_url }}" + method: POST + body_format: json + body: + blocks: + - type: section + text: + type: mrkdwn + text: This is a *_fancy_* message