Slack Callback Plugin Usage

407 views
Skip to first unread message

andrew...@xtra.co.nz

unread,
Dec 10, 2017, 6:26:30 PM12/10/17
to Ansible Project
I'm trying to use the Slack callback plugin (https://docs.ansible.com/ansible/devel/plugins/callback/slack.html) in the hopes that it will send notifications as a playbook is executed and when it completes successfully or otherwise.

Unfortunately the documentation is poor bordering on non-existant.  What I have been able to glean is:

  1. Install prettytable python library
  2. Update ansible.cfg with "callback_whitelist = slack"
From there it all gets a bit murky.  I should be able to setup some ini entries - no idea where so I took a wild guess and added this to ansible.cfg

[callback_slack]
webhook_url = https://hooks.slack.com/services/<my>/<slack>/<token>
channel = #preprod

Which gives this error when running a playbook:

ERROR! Unexpected Exception, this is probably a bug: 'webook_url'
the full traceback was:
Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 106, in <module>
    exit_code = cli.run()
  File "/usr/lib/python2.7/site-packages/ansible/cli/playbook.py", line 130, in run
    results = pbex.run()
  File "/usr/lib/python2.7/site-packages/ansible/executor/playbook_executor.py", line 90, in run
    self._tqm.load_callbacks()
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 202, in load_callbacks
    callback_obj = callback_plugin()
  File "/usr/lib/python2.7/site-packages/ansible/plugins/callback/slack.py", line 93, in __init__
    self.webhook_url = self._plugin_options['webook_url']
KeyError: 'webook_url'


Apart from getting this to work my other requirement that I'm not sure how to meet is how to I set the channel to match the name of the inventory I'm deploying to? Ideally I'd set the ini setting to something like "{{ inventory_dir|basename }}" but not sure if it would support that.  Otherwise I need to set "env:SLACK_CHANNEL" which I don't know how to do in Ansible.

NOTE: My playbooks are targeting windows hosts.
 
Versions:
ansible-playbook 2.4.0.0
python version = 2.7.5 (default, Aug  2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]

Thanks
  Andrew

Matt Martz

unread,
Dec 11, 2017, 10:33:26 AM12/11/17
to ansible...@googlegroups.com
That error has been fixed as of 2.4.1.  Please try upgrading and test again.  2.4.2 is the current stable release.

After upgrading, I believe everything should work as you have configured it.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/06b140de-4b65-4a99-be98-ddfb01e3f149%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages