Repository: ansible/ansible

Issue:
'slack' callback plugin not working
<!---
Verify first that your issue/request is not already reported on GitHub.
THIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.
Also test if the latest release, and devel branch are affected too.
ALWAYS add information AFTER (OUTSIDE) these html comments.
Otherwise it may end up being automatically closed by our bot. -->

##### SUMMARY 
ansible-playbook with slack module produces an error in callback plugin

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
slack.CallbackModule

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.6.1
  config file = /Users/mikejames/GitHub/ConfigurationManagement/ansible/ansible.cfg
  configured module search path = [u'/Users/mikejames/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.6.1/libexec/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.15 (default, Jun 17 2018, 12:46:58) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)]
```

##### CONFIGURATION
<!--- If using Ansible 2.4 or above, paste, BELOW THIS COMMENT, the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).-->
```
DEFAULT_CALLBACK_PLUGIN_PATH(/Users/mikejames/GitHub/ConfigurationManagement/ansible/ansible.cfg) = [u'/Users/mikejames/GitHub/ConfigurationManagement/ansible/playbooks/callback_plugins']
DEFAULT_CALLBACK_WHITELIST(/Users/mikejames/GitHub/ConfigurationManagement/ansible/ansible.cfg) = ['profile_tasks', 'timer', 'slack']
DEFAULT_HOST_LIST(/Users/mikejames/GitHub/ConfigurationManagement/ansible/ansible.cfg) = [u'/Users/mikejames/GitHub/ConfigurationManagement/ansible/inventory']
DEFAULT_LOG_PATH(/Users/mikejames/GitHub/ConfigurationManagement/ansible/ansible.cfg) = /Users/mikejames/GitHub/ConfigurationManagement/ansible/logs/ansible.log
DEFAULT_ROLES_PATH(/Users/mikejames/GitHub/ConfigurationManagement/ansible/ansible.cfg) = [u'/Users/mikejames/GitHub/ConfigurationManagement/ansible/playbooks/roles']
HOST_KEY_CHECKING(/Users/mikejames/GitHub/ConfigurationManagement/ansible/ansible.cfg) = False
```

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.-->
macOS High Sierra 10.13.6

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->

https://gist.github.com/tightly-clutched/05a40814d3271b51a6530163e3209299
<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
I expected a result to be posted to slack channel

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
playbook execution failed 

<!--- Paste verbatim command output between quotes below -->
https://gist.github.com/tightly-clutched/05a40814d3271b51a6530163e3209299


Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
I believe a change like the following needs to be made:

```diff
diff --git a/lib/ansible/plugins/callback/slack.py b/lib/ansible/plugins/callback/slack.py
index 4638c1b743..d59c029e9c 100644
--- a/lib/ansible/plugins/callback/slack.py
+++ b/lib/ansible/plugins/callback/slack.py
@@ -74,6 +74,11 @@ class CallbackModule(CallbackBase):
 
     def __init__(self, display=None):
 
+        if cli:
+            self._cli_options = cli.options
+        else:
+            self._cli_options = None
+
         super(CallbackModule, self).__init__(display=display)
 
         if not HAS_PRETTYTABLE:
@@ -132,13 +137,13 @@ class CallbackModule(CallbackBase):
             '*Playbook initiated* (_%s_)' % self.guid
         ]
         invocation_items = []
-        if self._plugin_options and self.show_invocation:
-            tags = self.get_option('tags')
-            skip_tags = self.get_option('skip_tags')
-            extra_vars = self.get_option('extra_vars')
-            subset = self.get_option('subset')
+        if self._cli_options and self.show_invocation:
+            tags = self._cli_options.tags
+            skip_tags = self._cli_options.skip_tags
+            extra_vars = self._cli_options.extra_vars
+            subset = self._cli_options.subset
             inventory = os.path.basename(
-                os.path.realpath(self.get_option('inventory'))
+                os.path.realpath(self._cli_options.inventory)
             )
 
             invocation_items.append('Inventory:  %s' % inventory)
@@ -152,7 +157,7 @@ class CallbackModule(CallbackBase):
                 invocation_items.append('Extra Vars: %s' %
                                         ' '.join(extra_vars))
 
-            title.append('by *%s*' % self.get_option('remote_user'))
+            title.append('by *%s*' % self._cli_options.remote_user)
 
         title.append('\n\n*%s*' % self.playbook_name)
         msg_items = [' '.join(title)]
```

I think some things were errantly changed over to use the plugin options functionality, that are not accessible.

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
@@ -76,6 +76,8 @@ def __init__(self, display=None):
 
         super(CallbackModule, self).__init__(display=display)
 
+        self._options = cli.options
+
         if not HAS_PRETTYTABLE:
             self.disabled = True
             self._display.warning('The `prettytable` python module is not '
@@ -132,27 +134,25 @@ def v2_playbook_on_start(self, playbook):
             '*Playbook initiated* (_%s_)' % self.guid
         ]
         invocation_items = []
-        if self._plugin_options and self.show_invocation:
-            tags = self.get_option('tags')
-            skip_tags = self.get_option('skip_tags')
-            extra_vars = self.get_option('extra_vars')
-            subset = self.get_option('subset')
-            inventory = os.path.basename(
-                os.path.realpath(self.get_option('inventory'))
-            )
-
-            invocation_items.append('Inventory:  %s' % inventory)
-            if tags and tags != 'all':
-                invocation_items.append('Tags:       %s' % tags)
+        if self._options and self.show_invocation:
+            tags = self._options.tags
+            skip_tags = self._options.skip_tags
+            extra_vars = self._options.extra_vars
+            subset = self._options.subset
+            inventory = [os.path.abspath(i) for i in self._options.inventory]
+
+            invocation_items.append('Inventory:  %s' % ', '.join(inventory))
+            if tags and tags != ['all']:
+                invocation_items.append('Tags:       %s' % ', '.join(tags))
             if skip_tags:
-                invocation_items.append('Skip Tags:  %s' % skip_tags)
+                invocation_items.append('Skip Tags:  %s' % ', '.join(skip_tags))
             if subset:
                 invocation_items.append('Limit:      %s' % subset)
             if extra_vars:
                 invocation_items.append('Extra Vars: %s' %
                                         ' '.join(extra_vars))
 
-            title.append('by *%s*' % self.get_option('remote_user'))
+            title.append('by *%s*' % self._options.remote_user)
 
         title.append('\n\n*%s*' % self.playbook_name)
         msg_items = [' '.join(title)]


Test patch: