Update www-check-available-updates.yaml
This commit is contained in:
58
www-check-available-updates.yaml
Normal file
58
www-check-available-updates.yaml
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user