Repository: ansible/ansible-lint

Issue:
UnicodeEncodeError on non-ascii characters
# Issue Type
- Bug report

# Ansible and Ansible Lint details

```
ansible 2.2.1.0
ansible-lint 3.4.10
```

- ansible installation method: pip
- ansible-lint installation method: pip

# Desired Behaviour

ansible-lint should handle non-ascii characters without failing

# Actual Behaviour (Bug report only)

I am purposefully testing a playbook that contains non-ascii characters as part of integration tests that ensures that an Ansible callback plugin/application can handle them properly. The playbook is the [following](https://github.com/openstack/ara/blob/master/ara/tests/integration/failed.yml):

```
- name: Failed playbook
  hosts: localhost
  tasks:
    - fail:
        msg: "This is a failed playbook with non-ascii characters: ä, ö, ü"
```

While running ansible-playbook --syntax-check returns fine, running ansible-lint on that file yields a UnicodeEncodeError:

```
$ ansible-lint ara/tests/integration/failed.yml 
Traceback (most recent call last):
  File "/home/dmsimard/dev/ara/.tox/ansible-lint/bin/ansible-lint", line 11, in <module>
    sys.exit(main())
  File "/home/dmsimard/dev/ara/.tox/ansible-lint/lib/python2.7/site-packages/ansiblelint/main/__init__.py", line 121, in main
    matches.extend(runner.run())
  File "/home/dmsimard/dev/ara/.tox/ansible-lint/lib/python2.7/site-packages/ansiblelint/__init__.py", line 243, in run
    skip_list=set(self.skip_list)))
  File "/home/dmsimard/dev/ara/.tox/ansible-lint/lib/python2.7/site-packages/ansiblelint/__init__.py", line 144, in run
    matches.extend(rule.matchtasks(playbookfile, text))
  File "/home/dmsimard/dev/ara/.tox/ansible-lint/lib/python2.7/site-packages/ansiblelint/__init__.py", line 80, in matchtasks
    taskstr = "Task/Handler: " + ansiblelint.utils.task_to_str(task)
  File "/home/dmsimard/dev/ara/.tox/ansible-lint/lib/python2.7/site-packages/ansiblelint/utils.py", line 443, in task_to_str
    if k not in ["__ansible_module__", "__ansible_arguments__"]] +
UnicodeEncodeError: 'ascii' codec can't encode characters in position 52-53: ordinal not in range(128)
```




Discussion:

Resolving patch:
diff --git a/lib/ansiblelint/utils.py b/lib/ansiblelint/utils.py
--- a/lib/ansiblelint/utils.py
+++ b/lib/ansiblelint/utils.py
@@ -439,10 +439,10 @@ def task_to_str(task):
     if name:
         return name
     action = task.get("action")
-    args = " " .join(["{0}={1}".format(k, v) for (k, v) in action.items()
+    args = " " .join([u"{0}={1}".format(k, v) for (k, v) in action.items()
                      if k not in ["__ansible_module__", "__ansible_arguments__"]] +
                      action.get("__ansible_arguments__"))
-    return "{0} {1}".format(action["__ansible_module__"], args)
+    return u"{0} {1}".format(action["__ansible_module__"], args)
 
 
 def extract_from_list(blocks, candidates):
diff --git a/lib/ansiblelint/version.py b/lib/ansiblelint/version.py
--- a/lib/ansiblelint/version.py
+++ b/lib/ansiblelint/version.py
@@ -1 +1 @@
-__version__ = '3.4.10'
+__version__ = '3.4.11'


Test patch:
diff --git a/test/TestUtils.py b/test/TestUtils.py
--- a/test/TestUtils.py
+++ b/test/TestUtils.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
 # Copyright (c) 2013-2014 Will Thames <will@thames.id.au>
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -119,3 +121,8 @@ def test_existing_filter_on_unknown_var(self):
         v = "{{ hello | to_json }}"
         result = utils.template('/a/b/c', v, dict(playbook_dir='/a/b/c'))
         self.assertEqual(result, "{{ hello | to_json }}")
+
+    def test_task_to_str_unicode(self):
+        task = dict(fail=dict(msg=u"unicode é ô à"))
+        result = utils.task_to_str(utils.normalize_task(task, 'filename.yml'))
+        self.assertEqual(result, u"fail msg=unicode é ô à")