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
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

View file

@ -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

View file

@ -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