来自Ansible的松弛消息以纯文本json的形式发送

时间:2019-01-24 14:33:28

标签: ansible slack slack-api

我正在使用Ansible通过ansible guidelines向Slack发送消息,但消息未格式化。例如,如果我有

- name: "Slack test"
    slack:
      token: "abc123"
      channel: "some_channel"
      color: good
      msg: '{"text": "This is a line of text.\nAnd this is another one."}'

在我的Ansible任务中,然后它将未格式化的json {"text": "This is a line of text.\nAnd this is another one."}发布到Slack频道。如何将JSON消息格式化为Slack's message formatting guide中的格式?

1 个答案:

答案 0 :(得分:2)

我认为您使用的Ansible语法不正确。

根据链接的文档,msg属性应直接包含消息的文本,而不是包含其他属性的JSON结构。

所以这应该是一个更正的示例:

- name: "Slack test"
    slack:
      token: "abc123"
      channel: "some_channel"
      color: good
      msg: "This is a line of text.\nAnd this is another one."

要为文本添加格式,您应该可以在msg属性中使用Slack标记。粗体示例:

- name: "Slack test"
        slack:
          token: "abc123"
          channel: "some_channel"
          color: good
          msg: "This is a *bold line* of text.\nAnd this is another one."