mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-04 17:53:10 +00:00
Use repr on replacements for only_if
This commit is contained in:
committed by
Michael DeHaan
parent
489844f960
commit
d181a64315
@@ -317,7 +317,7 @@ class Runner(object):
|
||||
new_args = new_args + "%s='%s' " % (k,v)
|
||||
module_args = new_args
|
||||
|
||||
conditional = utils.template(self.basedir, self.conditional, inject)
|
||||
conditional = utils.template(self.basedir, self.conditional, inject, do_repr=True)
|
||||
if not utils.check_conditional(conditional):
|
||||
result = utils.jsonify(dict(skipped=True))
|
||||
self.callbacks.on_skipped(host, inject.get('item',None))
|
||||
|
||||
@@ -209,7 +209,7 @@ def varLookup(varname, vars):
|
||||
except VarNotFoundException:
|
||||
return None
|
||||
|
||||
def varReplace(raw, vars):
|
||||
def varReplace(raw, vars, do_repr=False):
|
||||
''' Perform variable replacement of $variables in string raw using vars dictionary '''
|
||||
# this code originally from yum
|
||||
|
||||
@@ -230,6 +230,13 @@ def varReplace(raw, vars):
|
||||
replacement = m.group()
|
||||
|
||||
start, end = m.span()
|
||||
if do_repr:
|
||||
replacement = repr(replacement)
|
||||
if (start > 0 and
|
||||
((raw[start - 1] == "'" and raw[end] == "'") or
|
||||
(raw[start - 1] == '"' and raw[end] == '"'))):
|
||||
start -= 1
|
||||
end += 1
|
||||
done.append(raw[:start]) # Keep stuff leading up to token
|
||||
done.append(replacement) # Append replacement value
|
||||
raw = raw[end:] # Continue with remainder of string
|
||||
@@ -271,7 +278,7 @@ def varReplaceFilesAndPipes(basedir, raw):
|
||||
return ''.join(done)
|
||||
|
||||
|
||||
def template(basedir, text, vars):
|
||||
def template(basedir, text, vars, do_repr=False):
|
||||
''' run a text buffer through the templating engine until it no longer changes '''
|
||||
|
||||
prev_text = ''
|
||||
@@ -285,7 +292,7 @@ def template(basedir, text, vars):
|
||||
if (depth > 20):
|
||||
raise errors.AnsibleError("template recursion depth exceeded")
|
||||
prev_text = text
|
||||
text = varReplace(unicode(text), vars)
|
||||
text = varReplace(unicode(text), vars, do_repr)
|
||||
text = varReplaceFilesAndPipes(basedir, text)
|
||||
return text
|
||||
|
||||
|
||||
Reference in New Issue
Block a user