From c7368c2cb8d1e5a33c9eed2b81d36b12b2058e53 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 23 Feb 2016 13:12:38 -0500 Subject: [PATCH] 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 --- lib/ansible/executor/task_executor.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index e60ee5b71e3..f96eb578808 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -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