From 19386c43a7cedf611672887c7d469d0c5521a039 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 7 Oct 2013 10:02:21 -0400 Subject: [PATCH] Merge --- docsite/latest/rst/playbooks_loops.rst | 13 ------------- lib/ansible/runner/__init__.py | 7 +++++-- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/docsite/latest/rst/playbooks_loops.rst b/docsite/latest/rst/playbooks_loops.rst index 09f00cd98f2..426adeb8ab8 100644 --- a/docsite/latest/rst/playbooks_loops.rst +++ b/docsite/latest/rst/playbooks_loops.rst @@ -211,16 +211,6 @@ been retried for 5 times with a delay of 10 seconds. The default value for "retr The task returns the results returned by the last task run. The results of individual retries can be viewed by -vv option. The registered variable will also have a new key "attempts" which will have the number of the retries for the task. -The Do/Until feature does not take decision on whether to fail or pass the play when the maximum retries are completed, the user can -can do that in the next task as follows:: - - - action: shell /usr/bin/foo - register: result - until: result.stdout.find("all systems go") != -1 - retries: 5 - delay: 10 - failed_when: result.attempts == 5 - .. seealso:: :doc:`playbooks` @@ -239,6 +229,3 @@ can do that in the next task as follows:: #ansible IRC chat channel - - - diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index ac22fb1399c..a5a978d301f 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -660,7 +660,7 @@ class Runner(object): result = handler.run(conn, tmp, module_name, module_args, inject, complex_args) # Code for do until feature until = self.module_vars.get('until', None) - if until is not None and result.comm_ok: + if until is not None and result.comm_ok and "failed" not in result.result: inject[self.module_vars.get('register')] = result.result cond = template.template(self.basedir, until, inject, expand_lists=False) if not utils.check_conditional(cond, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars): @@ -674,12 +674,15 @@ class Runner(object): result = handler.run(conn, tmp, module_name, module_args, inject, complex_args) result.result['attempts'] = x vv("Result from run %i is: %s" % (x, result.result)) - if not result.comm_ok: + if "failed" in result.result: break inject[self.module_vars.get('register')] = result.result cond = template.template(self.basedir, until, inject, expand_lists=False) if utils.check_conditional(cond, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars): break + if result.result['attempts'] == retries and not utils.check_conditional(cond, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars): + result.result['failed'] = True + result.result['msg'] = "Task failed as maximum retries was encountered" else: result.result['attempts'] = 0 conn.close()