From c9bf7eb9bbff4e54398195256a1bcf86b3259cc4 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 25 Mar 2014 13:59:57 -0500 Subject: [PATCH] Don't run {failed|changed}_when checks until async_status is done Fixes #5117 --- lib/ansible/runner/__init__.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 3865b9c0b88..51655388aaf 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -849,16 +849,19 @@ class Runner(object): changed_when = self.module_vars.get('changed_when') failed_when = self.module_vars.get('failed_when') - if changed_when is not None or failed_when is not None: + if (changed_when is not None or failed_when is not None) and self.background == 0: register = self.module_vars.get('register') - if register is not None: + if register is not None: if 'stdout' in data: data['stdout_lines'] = data['stdout'].splitlines() inject[register] = data - if changed_when is not None: - data['changed'] = utils.check_conditional(changed_when, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars) - if failed_when is not None: - data['failed_when_result'] = data['failed'] = utils.check_conditional(failed_when, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars) + # only run the final checks if the async_status has finished, + # or if we're not running an async_status check at all + if (module_name == 'async_status' and "finished" in data) or module_name != 'async_status': + if changed_when is not None: + data['changed'] = utils.check_conditional(changed_when, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars) + if failed_when is not None: + data['failed_when_result'] = data['failed'] = utils.check_conditional(failed_when, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars) if is_chained: # no callbacks