Repository: ansible/ansible-modules-extras

Issue:
Slack - markdown when color defined
<!--- Verify first that your issue/request is not already reported in GitHub -->
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Bug Report
##### COMPONENT NAME

<!--- Name of the plugin/module/task -->

notification/slack.py
##### ANSIBLE VERSION

```
ansible 2.0.2.0
```
##### CONFIGURATION

<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

N/A
##### OS / ENVIRONMENT

<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->

N/A
##### SUMMARY

<!--- Explain the problem briefly -->

When using slack notifications with the any color option besides normal causes markdown to not be respected in slack.
##### STEPS TO REPRODUCE

<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->

```
    - name: Send Notification
      local_action:
        module: slack
        token: token/from/slack
        msg: "Ansible note for *{{ inventory_hostname }}*"
        parse: 'full'
        link_names: 1
        channel: "#ansible"
        color: warning
```

<!--- You can also paste gist.github.com links for larger files -->
##### EXPECTED RESULTS

I expect to see a message like

> Ansible note for - **hostname**

but instead see

> Ansible note for - *hostname*
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with high verbosity (-vvvv) -->

```
ok: [localhost -> localhost] => {"changed": false, "invocation": {"module_args": {"attachments": null, "channel": "#ansible", "color": "warning", "domain": null, "icon_emoji": null, "icon_url": "http://www.ansible.com/favicon.ico", "link_names": 1, "msg": "Ansible not for - *localhost*", "parse": null, "token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "username": "Ansible", "validate_certs": true}, "module_name": "slack"}, "msg": "OK"}
```

Slack - markdown when color defined
<!--- Verify first that your issue/request is not already reported in GitHub -->
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Bug Report
##### COMPONENT NAME

<!--- Name of the plugin/module/task -->

notification/slack.py
##### ANSIBLE VERSION

```
ansible 2.0.2.0
```
##### CONFIGURATION

<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

N/A
##### OS / ENVIRONMENT

<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->

N/A
##### SUMMARY

<!--- Explain the problem briefly -->

When using slack notifications with the any color option besides normal causes markdown to not be respected in slack.
##### STEPS TO REPRODUCE

<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->

```
    - name: Send Notification
      local_action:
        module: slack
        token: token/from/slack
        msg: "Ansible note for *{{ inventory_hostname }}*"
        parse: 'full'
        link_names: 1
        channel: "#ansible"
        color: warning
```

<!--- You can also paste gist.github.com links for larger files -->
##### EXPECTED RESULTS

I expect to see a message like

> Ansible note for - **hostname**

but instead see

> Ansible note for - *hostname*
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with high verbosity (-vvvv) -->

```
ok: [localhost -> localhost] => {"changed": false, "invocation": {"module_args": {"attachments": null, "channel": "#ansible", "color": "warning", "domain": null, "icon_emoji": null, "icon_url": "http://www.ansible.com/favicon.ico", "link_names": 1, "msg": "Ansible not for - *localhost*", "parse": null, "token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "username": "Ansible", "validate_certs": true}, "module_name": "slack"}, "msg": "OK"}
```



Discussion:

Resolving patch:
diff --git a/notification/slack.py b/notification/slack.py
--- a/notification/slack.py
+++ b/notification/slack.py
@@ -171,7 +171,8 @@ def build_payload_for_slack(module, text, channel, username, icon_url, icon_emoj
     if color == "normal" and text is not None:
         payload = dict(text=text)
     elif text is not None:
-        payload = dict(attachments=[dict(text=text, color=color)])
+        # With a custom color we have to set the message as attachment, and explicitely turn markdown parsing on for it.
+        payload = dict(attachments=[dict(text=text, color=color, mrkdwn_in=["text"])])
     if channel is not None:
         if (channel[0] == '#') or (channel[0] == '@'):
             payload['channel'] = channel


Test patch: