mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 03:00:23 -07:00
Fix for saving conditionals in variable expressions.
This commit is contained in:
parent
ca512c7d2f
commit
62b39d3de5
4 changed files with 14 additions and 7 deletions
|
@ -155,7 +155,16 @@ def is_changed(result):
|
|||
|
||||
return (result.get('changed', False) in [ True, 'True', 'true'])
|
||||
|
||||
def check_conditional(conditional):
|
||||
def check_conditional(conditional, basedir, inject):
|
||||
|
||||
if conditional.startswith("jinja2_compare"):
|
||||
conditional = conditional.replace("jinja2_compare ","")
|
||||
# allow variable names
|
||||
if conditional in inject:
|
||||
conditional = inject[conditional]
|
||||
conditional = template.template(basedir, conditional, inject)
|
||||
# a Jinja2 evaluation that results in something Python can eval!
|
||||
presented = "{% if " + conditional + " %} True {% else %} False {% endif %}"
|
||||
|
||||
if not isinstance(conditional, basestring):
|
||||
return conditional
|
||||
|
@ -667,9 +676,7 @@ def compile_when_to_only_if(expression):
|
|||
|
||||
# the stock 'when' without qualification (new in 1.2), assumes Jinja2 terms
|
||||
elif tokens[0] == 'jinja2_compare':
|
||||
# a Jinja2 evaluation that results in something Python can eval!
|
||||
presented = "{% if " + " ".join(tokens[1:]).strip() + " %} True {% else %} False {% endif %}"
|
||||
return presented
|
||||
return " ".join(tokens)
|
||||
else:
|
||||
raise errors.AnsibleError("invalid usage of when_ operator: %s" % expression)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue