1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixing/cleaning up do/until logic in TaskExecutor

* Fixes bug where the task was not marked as failed if the number of
  retries were exceeded (#14461)
* Reorganizing logic to be a bit cleaner, and so retrie messages are
  shown before sleeping (which makes way more sense)

Fixes #14461
Fixes #14580
This commit is contained in:
James Cammarata 2016-02-23 13:12:38 -05:00
parent cacb74aeeb
commit 6cf6130468

View file

@ -409,10 +409,6 @@ class TaskExecutor:
display.debug("starting attempt loop") display.debug("starting attempt loop")
result = None result = None
for attempt in range(retries): for attempt in range(retries):
if attempt > 0:
display.display("FAILED - RETRYING: %s (%d retries left). Result was: %s" % (self._task, retries-attempt, result), color=C.COLOR_DEBUG)
result['attempts'] = attempt + 1
display.debug("running the handler") display.debug("running the handler")
try: try:
result = self._handler.run(task_vars=variables) result = self._handler.run(task_vars=variables)
@ -469,16 +465,21 @@ class TaskExecutor:
_evaluate_failed_when_result(result) _evaluate_failed_when_result(result)
if attempt < retries - 1: if attempt < retries - 1:
if retries > 1:
result['attempts'] = attempt + 1
cond = Conditional(loader=self._loader) cond = Conditional(loader=self._loader)
cond.when = [ self._task.until ] cond.when = [ self._task.until ]
if cond.evaluate_conditional(templar, vars_copy): if cond.evaluate_conditional(templar, vars_copy):
break break
# no conditional check, or it failed, so sleep for the specified time # no conditional check, or it failed, so sleep for the specified time
display.display("FAILED - RETRYING: %s (%d retries left). Result was: %s" % (self._task, retries-(attempt+1), result), color=C.COLOR_DEBUG)
time.sleep(delay) time.sleep(delay)
else:
elif 'failed' not in result: if retries > 1:
break # we ran out of attempts, so mark the result as failed
result['attempts'] = retries
result['failed'] = True
# do the final update of the local variables here, for both registered # do the final update of the local variables here, for both registered
# values and any facts which may have been created # values and any facts which may have been created