From 9bb2a362893d80fb6900a3dcda50fbf8e1b4b3cf Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Tue, 10 Apr 2018 06:39:09 +1000 Subject: [PATCH] win_updates: backport 2.5 handle failure on module load (#38498) * win_updates: handle if module failed to run (#38363) (cherry picked from commit ccc56e138a1ed4a0bf5663f572fdec03bf89a2f4) * Added changelog fragment --- .../fragments/win_updates_handle-module-failures.yaml | 3 +++ lib/ansible/plugins/action/win_updates.py | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 changelogs/fragments/win_updates_handle-module-failures.yaml diff --git a/changelogs/fragments/win_updates_handle-module-failures.yaml b/changelogs/fragments/win_updates_handle-module-failures.yaml new file mode 100644 index 00000000000..044ed3bd08e --- /dev/null +++ b/changelogs/fragments/win_updates_handle-module-failures.yaml @@ -0,0 +1,3 @@ +bugfixes: +- win_updates - handle if the module fails to load and return the error message + https://github.com/ansible/ansible/pull/38363 diff --git a/lib/ansible/plugins/action/win_updates.py b/lib/ansible/plugins/action/win_updates.py index a3a0a050ece..09d51c2598d 100644 --- a/lib/ansible/plugins/action/win_updates.py +++ b/lib/ansible/plugins/action/win_updates.py @@ -186,6 +186,12 @@ class ActionModule(ActionBase): new_module_args.pop('reboot_timeout', None) result = self._run_win_updates(new_module_args, task_vars) + # if the module failed to run at all then changed won't be populated + # so we just return the result as is + # https://github.com/ansible/ansible/issues/38232 + if result['failed']: + return result + changed = result['changed'] updates = result.get('updates', dict()) filtered_updates = result.get('filtered_updates', dict()) @@ -235,6 +241,8 @@ class ActionModule(ActionBase): result.pop('msg', None) # rerun the win_updates module after the reboot is complete result = self._run_win_updates(new_module_args, task_vars) + if result['failed']: + return result result_updates = result.get('updates', dict()) result_filtered_updates = result.get('filtered_updates', dict())