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
pull/14899/head
James Cammarata 9 years ago
parent d7e3d7f3dc
commit c7368c2cb8

@ -409,10 +409,6 @@ class TaskExecutor:
display.debug("starting attempt loop")
result = None
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="dark gray")
result['attempts'] = attempt + 1
display.debug("running the handler")
try:
result = self._handler.run(task_vars=variables)
@ -469,16 +465,21 @@ class TaskExecutor:
_evaluate_failed_when_result(result)
if attempt < retries - 1:
if retries > 1:
result['attempts'] = attempt + 1
cond = Conditional(loader=self._loader)
cond.when = [ self._task.until ]
if cond.evaluate_conditional(templar, vars_copy):
break
# 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)
elif 'failed' not in result:
break
else:
if retries > 1:
# 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
# values and any facts which may have been created

Loading…
Cancel
Save