Makes $PIPE and $FILE macros accept utf-8 input

This commit is contained in:
Sébastien Bocahu 2013-04-06 22:00:12 +02:00
parent 20ec682b30
commit b94bf051d5
3 changed files with 4 additions and 3 deletions

View file

@ -17,6 +17,7 @@
from ansible import utils, errors from ansible import utils, errors
import os import os
import codecs
class LookupModule(object): class LookupModule(object):
@ -31,5 +32,5 @@ class LookupModule(object):
path = utils.path_dwim(self.basedir, term) path = utils.path_dwim(self.basedir, term)
if not os.path.exists(path): if not os.path.exists(path):
raise errors.AnsibleError("%s does not exist" % 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 return ret

View file

@ -31,7 +31,7 @@ class LookupModule(object):
p = subprocess.Popen(term, cwd=self.basedir, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) p = subprocess.Popen(term, cwd=self.basedir, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
(stdout, stderr) = p.communicate() (stdout, stderr) = p.communicate()
if p.returncode == 0: if p.returncode == 0:
ret.append(stdout.rstrip()) ret.append(stdout.decode("utf-8").rstrip())
else: else:
raise errors.AnsibleError("lookup_plugin.pipe(%s) returned %d" % (term, p.returncode)) raise errors.AnsibleError("lookup_plugin.pipe(%s) returned %d" % (term, p.returncode))
return ret return ret

View file

@ -176,7 +176,7 @@ def _varFind(basedir, text, vars, lookup_fatal, depth, expand_lists):
try: try:
replacement = instance.run(args, inject=vars) replacement = instance.run(args, inject=vars)
if expand_lists: if expand_lists:
replacement = ",".join([str(x) for x in replacement]) replacement = ",".join([unicode(x) for x in replacement])
except: except:
if not lookup_fatal: if not lookup_fatal:
replacement = None replacement = None