allow per conditonal item debugging (#70966)

* allow per conditonal item debugging
* offloaded a bit from _check_c
pull/71357/head
Brian Coca 4 years ago committed by GitHub
parent b87944926d
commit f7ade8e61c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- Add which conditional is being evaluated at each step when debugging.

@ -88,16 +88,30 @@ class Conditional:
if hasattr(self, '_ds'):
ds = getattr(self, '_ds')
result = True
try:
for conditional in self.when:
if not self._check_conditional(conditional, templar, all_vars):
return False
# do evaluation
if conditional is None or conditional == '':
res = True
elif isinstance(conditional, bool):
res = conditional
else:
res = self._check_conditional(conditional, templar, all_vars)
# only update if still true, preserve false
if result:
result = res
display.debug("Evaluated conditional (%s): %s " % (conditional, res))
if not result:
break
except Exception as e:
raise AnsibleError(
"The conditional check '%s' failed. The error was: %s" % (to_native(conditional), to_native(e)), obj=ds
)
raise AnsibleError("The conditional check '%s' failed. The error was: %s" % (to_native(conditional), to_native(e)), obj=ds)
return True
return result
def _check_conditional(self, conditional, templar, all_vars):
'''
@ -107,12 +121,6 @@ class Conditional:
'''
original = conditional
if conditional is None or conditional == '':
return True
# this allows for direct boolean assignments to conditionals "when: False"
if isinstance(conditional, bool):
return conditional
if templar.is_template(conditional):
display.warning('conditional statements should not include jinja2 '

Loading…
Cancel
Save