mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #1147 from dhozac/filepipe-exception
Raise AnsibleError if $FILE() or $PIPE() fail
This commit is contained in:
commit
e442175a9e
1 changed files with 10 additions and 7 deletions
|
@ -334,19 +334,22 @@ def varReplaceFilesAndPipes(basedir, raw):
|
||||||
# Determine replacement value (if unknown variable then preserve
|
# Determine replacement value (if unknown variable then preserve
|
||||||
# original)
|
# original)
|
||||||
|
|
||||||
|
replacement = m.group()
|
||||||
if m.group(1) == "FILE":
|
if m.group(1) == "FILE":
|
||||||
|
path = path_dwim(baesdir, m.group(2))
|
||||||
try:
|
try:
|
||||||
f = open(path_dwim(basedir, m.group(2)), "r")
|
f = open(path, "r")
|
||||||
|
replacement = f.read()
|
||||||
|
f.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
raise VarNotFoundException()
|
raise errors.AnsibleError("$FILE(%s) failed" % path)
|
||||||
replacement = f.read()
|
|
||||||
f.close()
|
|
||||||
elif m.group(1) == "PIPE":
|
elif m.group(1) == "PIPE":
|
||||||
p = subprocess.Popen(m.group(2), shell=True, stdout=subprocess.PIPE)
|
p = subprocess.Popen(m.group(2), shell=True, stdout=subprocess.PIPE)
|
||||||
(stdout, stderr) = p.communicate()
|
(stdout, stderr) = p.communicate()
|
||||||
if p.returncode != 0:
|
if p.returncode == 0:
|
||||||
raise VarNotFoundException()
|
replacement = stdout
|
||||||
replacement = stdout
|
else:
|
||||||
|
raise errors.AnsibleError("$PIPE(%s) returned %d" % (m.group(2), p.returncode))
|
||||||
|
|
||||||
start, end = m.span()
|
start, end = m.span()
|
||||||
done.append(raw[:start]) # Keep stuff leading up to token
|
done.append(raw[:start]) # Keep stuff leading up to token
|
||||||
|
|
Loading…
Reference in a new issue