From 083ce72ea4d9815ebdb9e947b26be1db5dd31756 Mon Sep 17 00:00:00 2001 From: mhorak Date: Wed, 6 Aug 2025 10:46:19 +0000 Subject: [PATCH] Add check-available-updates.yaml --- check-available-updates.yaml | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 check-available-updates.yaml diff --git a/check-available-updates.yaml b/check-available-updates.yaml new file mode 100644 index 0000000..2965b02 --- /dev/null +++ b/check-available-updates.yaml @@ -0,0 +1,58 @@ +- name: Windows Update Assessment and Reporting + hosts: windows + gather_facts: false + tasks: + - name: Ensure temporary directory exists + win_file: + path: C:\Temp + state: directory + - name: Scan for available Windows updates + win_updates: + state: searched + category_names: '*' + register: avail_updates + - name: Process and format update information + set_fact: + formatted_kb_updates: | + {% for update_id, update in avail_updates.updates.items() %} + {% if update.kb | length > 0 %} + {% set major_category = update.categories | reject('match', '.*Windows Server.*') | first | default('Unknown') %} + Major Category: {{ major_category }} + Title: {{ update.title }} + KB: {{ update.kb | join(', ') }} + --- + {% endif %} + {% endfor %} + formatted_non_kb_updates: | + {% for update_id, update in avail_updates.updates.items() %} + {% if update.kb | length == 0 %} + Title: {{ update.title }} + ID: {{ update.id }} + Categories: {{ update.categories | join(', ') }} + --- + {% endif %} + {% endfor %} + has_non_kb_updates: >- + {% set non_kb_count = [] %} + {% for update_id, update in avail_updates.updates.items() %} + {% if update.kb | length == 0 %} + {% set _ = non_kb_count.append(1) %} + {% endif %} + {% endfor %} + {{ non_kb_count | length > 0 }} + - name: Show available updates with KB numbers + debug: + msg: "{{ formatted_kb_updates.split('\n') }}" + - name: Show updates without KB numbers (if any) + debug: + msg: "Updates without KB numbers:\n{{ formatted_non_kb_updates.split('\n') }}" + when: has_non_kb_updates | bool + - name: Save KB updates report to file + ansible.windows.win_copy: + content: "{{ formatted_kb_updates }}" + dest: C:\Temp\windows_updates_with_kb.txt + - name: Save non-KB updates report to file + ansible.windows.win_copy: + content: "{{ formatted_non_kb_updates }}" + dest: C:\Temp\windows_updates_without_kb.txt + when: has_non_kb_updates | bool \ No newline at end of file