Cannot send Slack notification via Ansible

Viewed 31

I'm trying to send a Slack notification via Ansible:

- name: Send a custom slack notification
  run_once: true
  slack:
    #s3_backups Slack channel
    token: token/stuff/here
    attachments:
      - text: "S3 Web Server Config Backup Complete."
        title: S3 Web Server Backups
        color: "#8FCC2C"
  delegate_to: localhost

However, I'm getting a fatal error:

TASK [s3_fsn_backend_config_backup : Send a custom slack notification] ********************************************************************************************************************************************
Sorry, try again.
Sorry, try again.
fatal: [webserver-name -> localhost]: FAILED! => {"changed": false, "module_stderr": "[sudo via ansible, key=blahblahblahblahblah] password:[sudo via ansible, key=blahblahblahblahblah] password:sudo: 3 incorrect password attempts\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Am I using incorrect syntax? I just want it to run from localhost. I definitely don't understand what the Sorry, try again message means.

1 Answers

You can try the following code snippet

- name: Send slack notifications
  slack:
    token: "{{ slack_token }}"
    msg: "Hello World"
    channel: "#general"
    username: "Ansible"
    icon_url: "https://www.ansible.com/favicon.ico"
    link_names: 1
    parse: "full"
    color: "#00ff00"
    attachments:
      - text: "This is an attachment"
        color: "#ff0000"
        fields:
          - title: "Field 1"
            value: "This is an attachment"
            short: false
          - title: "Field 2"
            value: "This is an attachment"
            short: false
        footer: "Footer"
        footer_icon: "https://www.ansible.com/favicon.ico"
        ts: 123456789

More details available at slack_module

Related