Commit e442175a by Michael DeHaan

Merge pull request #1147 from dhozac/filepipe-exception

Raise AnsibleError if $FILE() or $PIPE() fail
parents 78911f1b e655e2f0
......@@ -334,19 +334,22 @@ def varReplaceFilesAndPipes(basedir, raw):
# Determine replacement value (if unknown variable then preserve
# original)
replacement = m.group()
if m.group(1) == "FILE":
path = path_dwim(baesdir, m.group(2))
try:
f = open(path_dwim(basedir, m.group(2)), "r")
f = open(path, "r")
replacement = f.read()
f.close()
except IOError:
raise VarNotFoundException()
replacement = f.read()
f.close()
raise errors.AnsibleError("$FILE(%s) failed" % path)
elif m.group(1) == "PIPE":
p = subprocess.Popen(m.group(2), shell=True, stdout=subprocess.PIPE)
(stdout, stderr) = p.communicate()
if p.returncode != 0:
raise VarNotFoundException()
replacement = stdout
if p.returncode == 0:
replacement = stdout
else:
raise errors.AnsibleError("$PIPE(%s) returned %d" % (m.group(2), p.returncode))
start, end = m.span()
done.append(raw[:start]) # Keep stuff leading up to token
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment