mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
Revert "Allow including files through variables"
This reverts commit bf47bb4753
.
Conflicts:
lib/ansible/utils.py
test/TestUtils.py
This commit is contained in:
parent
1bd9ea6440
commit
b8c4bb9e6e
9 changed files with 30 additions and 80 deletions
|
@ -31,7 +31,6 @@ import time
|
|||
import StringIO
|
||||
import imp
|
||||
import glob
|
||||
import subprocess
|
||||
|
||||
VERBOSITY=0
|
||||
|
||||
|
@ -183,7 +182,7 @@ def _varLookup(name, vars):
|
|||
_KEYCRE = re.compile(r"\$(?P<complex>\{){0,1}((?(complex)[\w\.\[\]]+|\w+))(?(complex)\})")
|
||||
|
||||
def varLookup(varname, vars):
|
||||
''' helper function used by with_items '''
|
||||
''' helper function used by varReplace '''
|
||||
|
||||
m = _KEYCRE.search(varname)
|
||||
if not m:
|
||||
|
@ -207,9 +206,10 @@ def varReplace(raw, vars):
|
|||
|
||||
# Determine replacement value (if unknown variable then preserve
|
||||
# original)
|
||||
varname = m.group(2)
|
||||
|
||||
try:
|
||||
replacement = unicode(_varLookup(m.group(2), vars))
|
||||
replacement = unicode(_varLookup(varname, vars))
|
||||
except VarNotFoundException:
|
||||
replacement = m.group()
|
||||
|
||||
|
@ -220,42 +220,7 @@ def varReplace(raw, vars):
|
|||
|
||||
return ''.join(done)
|
||||
|
||||
_FILEPIPECRE = re.compile(r"\$(?P<special>FILE|PIPE)\(([^\}]+)\)")
|
||||
def varReplaceFilesAndPipes(basedir, raw):
|
||||
done = [] # Completed chunks to return
|
||||
|
||||
while raw:
|
||||
m = _FILEPIPECRE.search(raw)
|
||||
if not m:
|
||||
done.append(raw)
|
||||
break
|
||||
|
||||
# Determine replacement value (if unknown variable then preserve
|
||||
# original)
|
||||
|
||||
if m.group(1) == "FILE":
|
||||
try:
|
||||
f = open(path_dwim(basedir, m.group(2)), "r")
|
||||
except IOError:
|
||||
raise VarNotFoundException()
|
||||
replacement = f.read()
|
||||
f.close()
|
||||
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
|
||||
|
||||
start, end = m.span()
|
||||
done.append(raw[:start]) # Keep stuff leading up to token
|
||||
done.append(replacement) # Append replacement value
|
||||
raw = raw[end:] # Continue with remainder of string
|
||||
|
||||
return ''.join(done)
|
||||
|
||||
|
||||
def template(basedir, text, vars):
|
||||
def template(text, vars):
|
||||
''' run a text buffer through the templating engine until it no longer changes '''
|
||||
|
||||
prev_text = ''
|
||||
|
@ -270,7 +235,6 @@ def template(basedir, text, vars):
|
|||
raise errors.AnsibleError("template recursion depth exceeded")
|
||||
prev_text = text
|
||||
text = varReplace(unicode(text), vars)
|
||||
text = varReplaceFilesAndPipes(basedir, text)
|
||||
return text
|
||||
|
||||
def template_from_file(basedir, path, vars):
|
||||
|
@ -287,7 +251,7 @@ def template_from_file(basedir, path, vars):
|
|||
res = t.render(vars)
|
||||
if data.endswith('\n') and not res.endswith('\n'):
|
||||
res = res + '\n'
|
||||
return template(basedir, res, vars)
|
||||
return template(res, vars)
|
||||
|
||||
def parse_yaml(data):
|
||||
''' convert a yaml string to a data structure '''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue