community.general.slack – Send Slack notifications
community.general.slack – Send Slack notifications
Note
This plugin is part of the community.general collection (version 1.3.2).
To install it use: ansible-galaxy collection install community.general
.
To use it in a playbook, specify: community.general.slack
.
Synopsis
- The
slack
module sends notifications to http://slack.com via the Incoming WebHook integration
Parameters
Parameter | Choices/Defaults | Comments |
---|---|---|
attachments list / elements=string |
Define a list of attachments. This list mirrors the Slack JSON API. For more information, see https://api.slack.com/docs/attachments. | |
blocks list / elements=dictionary added in 1.0.0 of community.general |
Define a list of blocks. This list mirrors the Slack JSON API. For more information, see https://api.slack.com/block-kit. | |
channel string |
Channel to send the message to. If absent, the message goes to the channel selected for the token. | |
color string |
Default: "normal" |
Allow text to use default colors - use the default of 'normal' to not send a custom color bar at the start of the message. Allowed values for color can be one of 'normal', 'good', 'warning', 'danger', any valid 3 digit or 6 digit hex color value. Specifying value in hex is supported since Ansible 2.8. |
domain string |
Slack (sub)domain for your environment without protocol. (i.e. | |
icon_emoji string |
Emoji for the message sender. See Slack documentation for options. (if icon_emoji is set, icon_url will not be used) | |
icon_url string |
Default: |
Url for the message sender's icon (default |
link_names integer |
Default: 1 |
Automatically create links for channels and usernames in msg. |
message_id string added in 1.2.0 of community.general |
Optional. Message ID to edit, instead of posting a new message. Corresponds to | |
msg string |
Message to send. Note that the module does not handle escaping characters. Plain-text angle brackets and ampersands should be converted to HTML entities (e.g. & to &) before sending. See Slack's documentation (https://api.slack.com/docs/message-formatting) for more. | |
parse string |
|
Setting for the message parser at Slack |
thread_id string |
Optional. Timestamp of parent message to thread this message. https://api.slack.com/docs/message-threading | |
token string / required |
Slack integration token. This authenticates you to the slack service. Make sure to use the correct type of token, depending on what method you use. Webhook token: Prior to 1.8, a token looked like WebAPI token: Slack WebAPI requires a personal, bot or work application token. These tokens start with | |
username string |
Default: "Ansible" |
This is the sender of the message. |
validate_certs boolean |
|
If |
Examples
- name: Send notification message via Slack
community.general.slack:
token: thetoken/generatedby/slack
msg: '{{ inventory_hostname }} completed'
delegate_to: localhost
- name: Send notification message via Slack all options
community.general.slack:
token: thetoken/generatedby/slack
msg: '{{ inventory_hostname }} completed'
channel: '#ansible'
thread_id: '1539917263.000100'
username: 'Ansible on {{ inventory_hostname }}'
icon_url: http://www.example.com/some-image-file.png
link_names: 0
parse: 'none'
delegate_to: localhost
- name: Insert a color bar in front of the message for visibility purposes and use the default webhook icon and name configured in Slack
community.general.slack:
token: thetoken/generatedby/slack
msg: '{{ inventory_hostname }} is alive!'
color: good
username: ''
icon_url: ''
- name: Insert a color bar in front of the message with valid hex color value
community.general.slack:
token: thetoken/generatedby/slack
msg: 'This message uses color in hex value'
color: '#00aacc'
username: ''
icon_url: ''
- name: Use the attachments API
community.general.slack:
token: thetoken/generatedby/slack
attachments:
- text: Display my system load on host A and B
color: '#ff00dd'
title: System load
fields:
- title: System A
value: "load average: 0,74, 0,66, 0,63"
short: True
- title: System B
value: 'load average: 5,16, 4,64, 2,43'
short: True
- name: Use the blocks API
community.general.slack:
token: thetoken/generatedby/slack
blocks:
- type: section
text:
type: mrkdwn
text: |-
*System load*
Display my system load on host A and B
- type: context
elements:
- type: mrkdwn
text: |-
*System A*
load average: 0,74, 0,66, 0,63
- type: mrkdwn
text: |-
*System B*
load average: 5,16, 4,64, 2,43
- name: Send a message with a link using Slack markup
community.general.slack:
token: thetoken/generatedby/slack
msg: We sent this message using <https://www.ansible.com|Ansible>!
- name: Send a message with angle brackets and ampersands
community.general.slack:
token: thetoken/generatedby/slack
msg: This message has <brackets> & ampersands in plain text.
- name: Initial Threaded Slack message
community.general.slack:
channel: '#ansible'
token: xoxb-1234-56789abcdefghijklmnop
msg: 'Starting a thread with my initial post.'
register: slack_response
- name: Add more info to thread
community.general.slack:
channel: '#ansible'
token: xoxb-1234-56789abcdefghijklmnop
thread_id: "{{ slack_response['ts'] }}"
color: good
msg: 'And this is my threaded response!'
- name: Send a message to be edited later on
community.general.slack:
token: thetoken/generatedby/slack
channel: '#ansible'
msg: Deploying something...
register: slack_response
- name: Edit message
community.general.slack:
token: thetoken/generatedby/slack
channel: "{{ slack_response.channel }}"
msg: Deployment complete!
message_id: "{{ slack_response.ts }}"
Authors
- Ramon de la Fuente (@ramondelafuente)
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.10/collections/community/general/slack_module.html