{"id":6434,"date":"2020-08-17T09:09:45","date_gmt":"2020-08-17T15:09:45","guid":{"rendered":"http:\/\/gregsowell.com\/?p=6434"},"modified":"2020-08-12T09:10:11","modified_gmt":"2020-08-12T15:10:11","slug":"formatting-slack-messages-sent-by-ansible","status":"publish","type":"post","link":"https:\/\/gregsowell.com\/?p=6434","title":{"rendered":"Formatting Slack Messages Sent By Ansible"},"content":{"rendered":"<p>I&#8217;ve been sending some messages via ansible playbooks to slack and I ran into issues when I tried sending clickable links.  Luckily the <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/modules\/slack_module.html\">ansible slack module <\/a>has the options you need.<\/p>\n<p>Here&#8217;s an example of sending a standard message:<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">    - name: send message through slack\r\n      slack:\r\n        token: &quot;{{ slack_token }}&quot;\r\n        msg: |\r\n          &quot;http:\/\/GregSowell.com&quot;\r\n          &quot;This is a great site&quot;\r\n        channel: &quot;{{ slack_channel }}&quot;\r\n        parse: &#039;none&#039;\r\n      delegate_to: localhost<\/code><\/pre>\n<p>Unfortunately the URL above just shows up as standard text and isn&#8217;t clickable.  <\/p>\n<p>I can instead use the attachments module to make it clickable like so:<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">    - name: send message through slack\r\n      slack:\r\n        token: &quot;{{ slack_token }}&quot;\r\n        attachments:\r\n          - text: This is a great site\r\n            title: &quot;Go to GregSowell.com&quot;\r\n            title_link: &quot;http:\/\/GregSowell.com&quot;\r\n        channel: &quot;{{ slack_channel }}&quot;\r\n        parse: &#039;none&#039;\r\n      delegate_to: localhost<\/code><\/pre>\n<p>Now slack creates an attachment post that has the text along with the title being a clickable link.<br \/>\n<a href=\"https:\/\/api.slack.com\/docs\/messages\/builder?msg=%7B%22attachments%22%3A%5B%7B%22fallback%22%3A%22Required%20plain-text%20summary%20of%20the%20attachment.%22%2C%22color%22%3A%22%2336a64f%22%2C%22pretext%22%3A%22Optional%20text%20that%20appears%20above%20the%20attachment%20block%22%2C%22author_name%22%3A%22Bobby%20Tables%22%2C%22author_link%22%3A%22http%3A%2F%2Fflickr.com%2Fbobby%2F%22%2C%22author_icon%22%3A%22http%3A%2F%2Fflickr.com%2Ficons%2Fbobby.jpg%22%2C%22title%22%3A%22Slack%20API%20Documentation%22%2C%22title_link%22%3A%22https%3A%2F%2Fapi.slack.com%2F%22%2C%22text%22%3A%22Optional%20text%20that%20appears%20within%20the%20attachment%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Priority%22%2C%22value%22%3A%22High%22%2C%22short%22%3Afalse%7D%5D%2C%22image_url%22%3A%22http%3A%2F%2Fmy-website.com%2Fpath%2Fto%2Fimage.jpg%22%2C%22thumb_url%22%3A%22http%3A%2F%2Fexample.com%2Fpath%2Fto%2Fthumb.png%22%2C%22footer%22%3A%22Slack%20API%22%2C%22footer_icon%22%3A%22https%3A%2F%2Fplatform.slack-edge.com%2Fimg%2Fdefault_application_icon.png%22%2C%22ts%22%3A123456789%7D%5D%7D\">Slack has an API message reference here <\/a>that helps build the above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been sending some messages via ansible playbooks to slack and I ran into issues when I tried sending clickable links. Luckily the ansible\u2026<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"class_list":["post-6434","post","type-post","status-publish","format-standard","hentry","category-ansible"],"_links":{"self":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/6434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6434"}],"version-history":[{"count":1,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/6434\/revisions"}],"predecessor-version":[{"id":6435,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/6434\/revisions\/6435"}],"wp:attachment":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}