Commit 829a88b9 by James Cammarata

Disable undefined error failures during conditional templating

This allows us to properly catch the 'is defined' and 'is undefined'
checks and return the correct boolean result.

Fixes #11892
parent e0b07400
...@@ -66,8 +66,6 @@ class Conditional: ...@@ -66,8 +66,6 @@ class Conditional:
for conditional in self.when: for conditional in self.when:
if not self._check_conditional(conditional, templar, all_vars): if not self._check_conditional(conditional, templar, all_vars):
return False return False
except UndefinedError, e:
raise AnsibleError("The conditional check '%s' failed due to an undefined variable. The error was: %s" % (conditional, e), obj=ds)
except Exception, e: except Exception, e:
raise AnsibleError("The conditional check '%s' failed. The error was: %s" % (conditional, e), obj=ds) raise AnsibleError("The conditional check '%s' failed. The error was: %s" % (conditional, e), obj=ds)
...@@ -96,7 +94,7 @@ class Conditional: ...@@ -96,7 +94,7 @@ class Conditional:
# a Jinja2 evaluation that results in something Python can eval! # a Jinja2 evaluation that results in something Python can eval!
presented = "{%% if %s %%} True {%% else %%} False {%% endif %%}" % conditional presented = "{%% if %s %%} True {%% else %%} False {%% endif %%}" % conditional
conditional = templar.template(presented) conditional = templar.template(presented, fail_on_undefined=False)
val = conditional.strip() val = conditional.strip()
if val == presented: if val == presented:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment