Windows: report from a post-install search, even on failure

- Re-search after installing; win_updates can list reboot-applied updates as not installed
- Wrap install in block/always so the pending report runs when an update fails
- Read reboot status from the post-install search

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
JustinandClaude Opus 5.5 committed 2026-11-17 15:32:00 -06:00
1 parent 8de2386aa1
commit abdca77860
1 file changed
+18 -5
+18 -5
View File
@@ -34,6 +34,9 @@
msg: "{{ search.updates | dict2items | map(attribute='value.title') | list }}"
when: search_only | bool
- name: Install updates and report
when: not search_only | bool
block:
- name: Install updates
ansible.windows.win_updates:
category_names: "{{ update_categories }}"
@@ -41,7 +44,6 @@
reboot: "{{ reboot | bool }}"
reboot_timeout: 3600
register: result
when: not search_only | bool
# With reboot=false, updates blocked by the pending restart (WU_E_INSTALL_NOT_ALLOWED)
# are expected; only fail on other errors.
failed_when: >-
@@ -51,10 +53,21 @@
| selectattr('failure_hresult_code', 'defined')
| rejectattr('failure_hresult_code', 'equalto', 2149842966) | list | length > 0)
# Runs even if the install failed, so a failed run still shows what is pending.
always:
# Re-search afterwards: win_updates marks updates that were staged for a reboot as
# "not installed" even after the reboot applies them, so this is the reliable view.
- name: Check what is still pending
ansible.windows.win_updates:
category_names: "{{ update_categories }}"
state: searched
register: after
- name: Report
vars:
reboot_pending: "{{ after.reboot_required | default(result.reboot_required | default(false)) | bool }}"
ansible.builtin.debug:
msg:
- "Installed: {{ result.updates | dict2items | map(attribute='value') | selectattr('installed') | map(attribute='title') | list }}"
- "Not installed: {{ result.updates | dict2items | map(attribute='value') | rejectattr('installed') | map(attribute='title') | list }}"
- "Reboot still required: {{ result.reboot_required }}{{ ' - reboot and re-run to finish' if result.reboot_required else '' }}"
when: not search_only | bool
- "Processed this run: {{ result.updates | default({}) | dict2items | map(attribute='value.title') | list }}"
- "Still pending: {{ after.updates | default({}) | dict2items | map(attribute='value.title') | list }}"
- "Reboot still required: {{ reboot_pending }}{{ ' - reboot and re-run to finish' if reboot_pending | bool else '' }}"