Repository: ansible/ansible

Issue:
fix typos in slack callback plugin
##### SUMMARY

There were two issues:

1. there was a typo in key name ('webook_url' vs 'webhook_url')
2. `_plugin_options` can be an empty dict, so we should use `.get()` instead of `[]`

##### ISSUE TYPE
 - Bugfix Pull Request

##### COMPONENT NAME
`plugins/callback/slack`

##### ANSIBLE VERSION
```
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/hiciu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Sep 20 2017, 01:25:59) [GCC 7.2.0]
```


##### ADDITIONAL INFORMATION
Before:
```
2017-09-25 14:01:12,741 p=46127 u=hiciu |   [WARNING]: The `prettytable` python module is not installed. Disabling the
Slack callback plugin.

2017-09-25 14:01:12,742 p=46127 u=hiciu |  ERROR! Unexpected Exception, this is probably a bug: 'webook_url'
2017-09-25 14:01:12,742 p=46127 u=hiciu |  to see the full traceback, use -vvv
2017-09-25 14:01:12,744 p=46127 u=hiciu |  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'
```

After:
```
2017-09-25 14:24:49,633 p=53921 u=hiciu |   [WARNING]: The `prettytable` python module is not installed. Disabling the
Slack callback plugin.
2017-09-25 14:24:49,634 p=53921 u=hiciu |   [WARNING]: Slack Webhook URL was not provided. The Slack Webhook URL can be
provided using the `SLACK_WEBHOOK_URL` environment variable.
```


Discussion:
@hiciu please make the PR against development, we will backport as needed.
@bcoca against devel branch, the one with last commit from Sep 21, 2016?

edit: wait a minute, github is playing a joke on me...
Sorry about that. I'll open new PR with proper base.
@hiciu np, also you can just 'force push' to this branch with the rebased branch
I tried to do that but looking at the ~250 commits that have been added I must've broke something along the way :). I'll fix it in a moment.

Resolving patch:
diff --git a/lib/ansible/plugins/callback/slack.py b/lib/ansible/plugins/callback/slack.py
--- a/lib/ansible/plugins/callback/slack.py
+++ b/lib/ansible/plugins/callback/slack.py
@@ -54,7 +54,6 @@
     cli = None
 
 from ansible.module_utils.urls import open_url
-from ansible.module_utils.parsing.convert_bool import boolean
 from ansible.plugins.callback import CallbackBase
 
 try:
@@ -75,13 +74,6 @@ class CallbackModule(CallbackBase):
 
     def __init__(self, display=None):
 
-        self.disabled = False
-
-        if cli:
-            self._plugin_options = cli.options
-        else:
-            self._plugin_options = None
-
         super(CallbackModule, self).__init__(display=display)
 
         if not HAS_PRETTYTABLE:
@@ -90,7 +82,18 @@ def __init__(self, display=None):
                                   'installed. Disabling the Slack callback '
                                   'plugin.')
 
-        self.webhook_url = self._plugin_options['webook_url']
+        self.playbook_name = None
+
+        # This is a 6 character identifier provided with each message
+        # This makes it easier to correlate messages when there are more
+        # than 1 simultaneous playbooks running
+        self.guid = uuid.uuid4().hex[:6]
+
+    def set_options(self, options):
+
+        super(CallbackModule, self).set_options(options)
+
+        self.webhook_url = self._plugin_options['webhook_url']
         self.channel = self._plugin_options['channel']
         self.username = self._plugin_options['username']
         self.show_invocation = (self._display.verbosity > 1)
@@ -102,14 +105,6 @@ def __init__(self, display=None):
                                   'the `SLACK_WEBHOOK_URL` environment '
                                   'variable.')
 
-        else:
-            self.playbook_name = None
-
-            # This is a 6 character identifier provided with each message
-            # This makes it easier to correlate messages when there are more
-            # than 1 simultaneous playbooks running
-            self.guid = uuid.uuid4().hex[:6]
-
     def send_msg(self, attachments):
         payload = {
             'channel': self.channel,


Test patch: