代码之家  ›  专栏  ›  技术社区  ›  TheStrangeQuark

来自ansible的可宽延消息作为纯文本json发送

  •  0
  • TheStrangeQuark  · 技术社区  · 6 年前

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

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

    在我负责的任务中,它将发布未格式化的JSON {"text": "This is a line of text.\nAnd this is another one."} 到松弛通道。如何让JSON消息的格式像 Slack's message formatting guide ?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Erik Kalkoken    6 年前

    我认为你没有用正确的语法来解释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属性中的松弛标记。粗体示例:

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