allow per conditonal item debugging (#70966)

* allow per conditonal item debugging
* offloaded a bit from _check_c
This commit is contained in:
Brian Coca 2020-08-19 12:55:17 -04:00 committed by GitHub
parent b87944926d
commit f7ade8e61c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 13 deletions

View file

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

View file

@ -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
except Exception as e:
raise AnsibleError(
"The conditional check '%s' failed. The error was: %s" % (to_native(conditional), to_native(e)), obj=ds
)
return True
# 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)
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 '