From 9bb8435ec9b4314d25b6f46360b59ac6f70ee650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Param=C3=A9s?= Date: Sat, 9 Mar 2013 03:27:45 +0000 Subject: [PATCH] Fixes #2346 --- lib/ansible/runner/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index a4f74c25d7..dd237c946e 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -206,7 +206,12 @@ class Runner(object): afd, afile = tempfile.mkstemp() afo = os.fdopen(afd, 'w') try: - afo.write(data.encode('utf8')) + if not isinstance(data, unicode): + #ensure the data is valid UTF-8 + data.decode('utf-8') + else: + data = data.encode('utf-8') + afo.write(data) except: raise errors.AnsibleError("failure encoding into utf-8") afo.flush()