stringify conditional before handing it to Jinja2 for evaluation.

This should fix simple conditionals like:

    when: ansible_selinux

While here add tests for ansible.utils.check_conditional() in
"jinja2_compare mode".
This commit is contained in:
Stoned Elipot
2013-07-23 22:24:53 +02:00
parent d1effecb2e
commit a1503c4d59
2 changed files with 95 additions and 1 deletions

View File

@@ -164,7 +164,7 @@ def check_conditional(conditional, basedir, inject, fail_on_undefined=False):
conditional = inject[conditional]
conditional = template.template(basedir, conditional, inject, fail_on_undefined=fail_on_undefined)
# a Jinja2 evaluation that results in something Python can eval!
presented = "{% if " + conditional + " %} True {% else %} False {% endif %}"
presented = "{%% if %s %%} True {%% else %%} False {%% endif %%}" % conditional
conditional = template.template(basedir, presented, inject)
val = conditional.lstrip().rstrip()
if val == "True":