From b94bf051d5b26933567365c6c3950cbb28058f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Bocahu?= Date: Sat, 6 Apr 2013 22:00:12 +0200 Subject: [PATCH] Makes $PIPE and $FILE macros accept utf-8 input --- lib/ansible/runner/lookup_plugins/file.py | 3 ++- lib/ansible/runner/lookup_plugins/pipe.py | 2 +- lib/ansible/utils/template.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ansible/runner/lookup_plugins/file.py b/lib/ansible/runner/lookup_plugins/file.py index 92fa9a7c932..df4a5561155 100644 --- a/lib/ansible/runner/lookup_plugins/file.py +++ b/lib/ansible/runner/lookup_plugins/file.py @@ -17,6 +17,7 @@ from ansible import utils, errors import os +import codecs class LookupModule(object): @@ -31,5 +32,5 @@ class LookupModule(object): path = utils.path_dwim(self.basedir, term) if not os.path.exists(path): raise errors.AnsibleError("%s does not exist" % path) - ret.append(open(path).read().rstrip()) + ret.append(codecs.open(path, encoding="utf8").read().rstrip()) return ret diff --git a/lib/ansible/runner/lookup_plugins/pipe.py b/lib/ansible/runner/lookup_plugins/pipe.py index 37ea97b5204..6a9d9dd2318 100644 --- a/lib/ansible/runner/lookup_plugins/pipe.py +++ b/lib/ansible/runner/lookup_plugins/pipe.py @@ -31,7 +31,7 @@ class LookupModule(object): p = subprocess.Popen(term, cwd=self.basedir, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) (stdout, stderr) = p.communicate() if p.returncode == 0: - ret.append(stdout.rstrip()) + ret.append(stdout.decode("utf-8").rstrip()) else: raise errors.AnsibleError("lookup_plugin.pipe(%s) returned %d" % (term, p.returncode)) return ret diff --git a/lib/ansible/utils/template.py b/lib/ansible/utils/template.py index 61edb2940ea..4158768787e 100644 --- a/lib/ansible/utils/template.py +++ b/lib/ansible/utils/template.py @@ -176,7 +176,7 @@ def _varFind(basedir, text, vars, lookup_fatal, depth, expand_lists): try: replacement = instance.run(args, inject=vars) if expand_lists: - replacement = ",".join([str(x) for x in replacement]) + replacement = ",".join([unicode(x) for x in replacement]) except: if not lookup_fatal: replacement = None