Skip to content
Aug 17 / Greg

Formatting Slack Messages Sent By Ansible

I’ve been sending some messages via ansible playbooks to slack and I ran into issues when I tried sending clickable links. Luckily the ansible slack module has the options you need.

Here’s an example of sending a standard message:

1
2
3
4
5
6
7
8
9
    - name: send message through slack
      slack:
        token: "{{ slack_token }}"
        msg: |
          "http://GregSowell.com"
          "This is a great site"
        channel: "{{ slack_channel }}"
        parse: 'none'
      delegate_to: localhost

Unfortunately the URL above just shows up as standard text and isn’t clickable.

I can instead use the attachments module to make it clickable like so:

1
2
3
4
5
6
7
8
9
10
    - name: send message through slack
      slack:
        token: "{{ slack_token }}"
        attachments:
          - text: This is a great site
            title: "Go to GregSowell.com"
            title_link: "http://GregSowell.com"
        channel: "{{ slack_channel }}"
        parse: 'none'
      delegate_to: localhost

Now slack creates an attachment post that has the text along with the title being a clickable link.
Slack has an API message reference here that helps build the above.

Leave a Comment

 

*