Repository: ansible/ansible

Issue:
unixy callback fails with warning when using 'non strings' in debug's msg
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and devel branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Bug Report

##### COMPONENT NAME
<!---
Name of the module, plugin, task or feature
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path
-->
`unixy` callback plugin

##### ANSIBLE VERSION
ansible 2.6.0
  config file = //ansible.cfg
  configured module search path = [u'/root/.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, Dec 14 2017, 15:51:29) [GCC 6.4.0]

##### CONFIGURATION
ANSIBLE_COW_SELECTION(//ansible.cfg) = random
ANSIBLE_COW_WHITELIST(//ansible.cfg) = ['bud-frogs', 'bunny', 'cheese', 'daemon', 'default', 'dragon', 'elephant-in-snake', 'elephant', 'eyes']
ANSIBLE_NOCOWS(//ansible.cfg) = False
CACHE_PLUGIN(//ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(//ansible.cfg) = /fact_cache
CACHE_PLUGIN_TIMEOUT(//ansible.cfg) = 86400
DEFAULT_CALLBACK_WHITELIST(//ansible.cfg) = ['unixy']
DEFAULT_GATHERING(//ansible.cfg) = explicit
DEFAULT_GATHER_TIMEOUT(//ansible.cfg) = 10
DEFAULT_STDOUT_CALLBACK(//ansible.cfg) = unixy
DEFAULT_TIMEOUT(//ansible.cfg) = 10
DISPLAY_SKIPPED_HOSTS(//ansible.cfg) = False
HOST_KEY_CHECKING(//ansible.cfg) = False
SHOW_CUSTOM_STATS(//ansible.cfg) = True

##### OS / ENVIRONMENT
CentOS 7.4

##### SUMMARY
Looks like `unixy` cannot handle debug module with multiline msg
```
 [WARNING]: Failure using method (v2_runner_on_ok) in callback plugin (<ansible.plugins.callback.unixy.CallbackModule object at 0x7f4b37080c50>): cannot concatenate 'str' and 'list' objects
```

##### STEPS TO REPRODUCE
Enable `unixy` callback plugin in `ansible.cfg`

```
callback_whitelist = unixy
stdout_callback = unixy
show_custom_stats = true
display_skipped_hosts = false
```

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- debug:
    msg:
      - "Hello"
      - "World"
```

##### EXPECTED RESULTS
No warning and the full debug msg output displayed on console output

##### ACTUAL RESULTS
Output does not get printied. Just a warning. Verbose `-vvvv` output below
```
debug...
 [WARNING]: Failure using method (v2_runner_on_ok) in callback plugin (<ansible.plugins.callback.unixy.CallbackModule object at 0x7f6d7257fc50>): cannot concatenate 'str' and 'list' objects

Callback Exception:
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 375, in send_callback
    method(*new_args, **kwargs)
   File "/usr/lib/python2.7/site-packages/ansible/plugins/callback/unixy.py", line 125, in v2_runner_on_ok
    task_result = self._process_result_output(result, msg)
   File "/usr/lib/python2.7/site-packages/ansible/plugins/callback/unixy.py", line 78, in _process_result_output
    task_result += " | msg: " + result._result.get('msg')

META: ran handlers
META: ran handlers
```



Discussion:
Files identified in the description:
* [lib/ansible/plugins/callback/unixy.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/unixy.py)

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 --->
cc @akatch
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/plugins/callback/unixy.py b/lib/ansible/plugins/callback/unixy.py
--- a/lib/ansible/plugins/callback/unixy.py
+++ b/lib/ansible/plugins/callback/unixy.py
@@ -20,10 +20,12 @@
       - set as stdout in configuration
 '''
 
+from os.path import basename
+
+from ansible import constants as C
+from ansible.module_utils._text import to_text
 from ansible.plugins.callback import CallbackBase
 from ansible.utils.color import colorize, hostcolor
-from ansible import constants as C
-from os.path import basename
 
 
 class CallbackModule(CallbackBase):
@@ -75,7 +77,7 @@ def _process_result_output(self, result, msg):
             task_result = "%s -> %s %s" % (task_host, task_delegate_host, msg)
 
         if result._result.get('msg') and result._result.get('msg') != "All items completed":
-            task_result += " | msg: " + result._result.get('msg')
+            task_result += " | msg: " + to_text(result._result.get('msg'))
 
         if result._result.get('stdout'):
             task_result += " | stdout: " + result._result.get('stdout')


Test patch: