allow per conditonal item debugging (#70966)
* allow per conditonal item debugging * offloaded a bit from _check_c
This commit is contained in:
parent
b87944926d
commit
f7ade8e61c
2 changed files with 23 additions and 13 deletions
2
changelogs/fragments/which_when_false.yml
Normal file
2
changelogs/fragments/which_when_false.yml
Normal file
|
@ -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'):
|
if hasattr(self, '_ds'):
|
||||||
ds = getattr(self, '_ds')
|
ds = getattr(self, '_ds')
|
||||||
|
|
||||||
|
result = True
|
||||||
try:
|
try:
|
||||||
for conditional in self.when:
|
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):
|
def _check_conditional(self, conditional, templar, all_vars):
|
||||||
'''
|
'''
|
||||||
|
@ -107,12 +121,6 @@ class Conditional:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
original = 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):
|
if templar.is_template(conditional):
|
||||||
display.warning('conditional statements should not include jinja2 '
|
display.warning('conditional statements should not include jinja2 '
|
||||||
|
|
Loading…
Reference in a new issue