Update www-install-win-updates.yaml
This commit is contained in:
@@ -24,7 +24,11 @@
|
|||||||
|
|
||||||
- name: Extract KB numbers from report file
|
- name: Extract KB numbers from report file
|
||||||
set_fact:
|
set_fact:
|
||||||
kb_numbers: "{{ updates_content.stdout_lines | select('match', '.*KB: .*') | map('regex_replace', '.*KB: ([0-9,\\s]+).*', '\\1') | map('split', ',') | flatten | map('trim') | select('match', '^[0-9]+$') | list | unique }}"
|
kb_numbers: "{{ updates_content.stdout_lines
|
||||||
|
| select('match', '.*KB: .*')
|
||||||
|
| map('regex_replace', '.*KB: ([0-9,\\s]+).*', '\\1')
|
||||||
|
| map('split', ',') | flatten | map('trim')
|
||||||
|
| select('match', '^[0-9]+$') | list | unique }}"
|
||||||
when:
|
when:
|
||||||
- kb_updates_file.stat.exists
|
- kb_updates_file.stat.exists
|
||||||
- updates_content.stdout_lines is defined
|
- updates_content.stdout_lines is defined
|
||||||
@@ -51,6 +55,16 @@
|
|||||||
- kb_numbers is defined
|
- kb_numbers is defined
|
||||||
- kb_numbers | length > 0
|
- kb_numbers | length > 0
|
||||||
|
|
||||||
|
- name: Mark host failed if any KB installs failed
|
||||||
|
set_fact:
|
||||||
|
patch_failed_host: "{{ (installation_result.failed_update_count | default(0) | int) > 0 }}"
|
||||||
|
patch_failed_count: "{{ installation_result.failed_update_count | default(0) | int }}"
|
||||||
|
when:
|
||||||
|
- kb_updates_file.stat.exists
|
||||||
|
- kb_numbers is defined
|
||||||
|
- kb_numbers | length > 0
|
||||||
|
- installation_result is defined
|
||||||
|
|
||||||
- name: Display installation summary
|
- name: Display installation summary
|
||||||
debug:
|
debug:
|
||||||
msg:
|
msg:
|
||||||
@@ -120,6 +134,8 @@
|
|||||||
- kb_updates_file.stat.exists
|
- kb_updates_file.stat.exists
|
||||||
- (kb_numbers is not defined or kb_numbers | length == 0)
|
- (kb_numbers is not defined or kb_numbers | length == 0)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
- name: Post patching results to SharePoint (Graph)
|
- name: Post patching results to SharePoint (Graph)
|
||||||
hosts: windows
|
hosts: windows
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
@@ -135,14 +151,13 @@
|
|||||||
job_id: "{{ tower_job_id | default('n/a') }}"
|
job_id: "{{ tower_job_id | default('n/a') }}"
|
||||||
job_name: "{{ tower_job_template_name | default('Patch run') }}"
|
job_name: "{{ tower_job_template_name | default('Patch run') }}"
|
||||||
job_url: "{{ tower_job_url | default('') }}"
|
job_url: "{{ tower_job_url | default('') }}"
|
||||||
status: "{{ (tower_job_failed | default(false)) | ternary('failed','successful') }}"
|
|
||||||
|
|
||||||
# Timestamps (avoid ansible_date_time since gather_facts: false)
|
# Timestamps (works without gather_facts)
|
||||||
run_start: "{{ lookup('pipe','date -u +%Y-%m-%dT%H:%M:%SZ') }}"
|
run_start: "{{ lookup('pipe','date -u +%Y-%m-%dT%H:%M:%SZ') }}"
|
||||||
run_end: "{{ lookup('pipe','date -u +%Y-%m-%dT%H:%M:%SZ') }}"
|
run_end: "{{ lookup('pipe','date -u +%Y-%m-%dT%H:%M:%SZ') }}"
|
||||||
|
|
||||||
summary_text: >-
|
summary_text: >-
|
||||||
Job {{ job_id }} {{ status }}.
|
Job {{ job_id }}.
|
||||||
Template={{ job_name }}.
|
Template={{ job_name }}.
|
||||||
URL={{ job_url }}.
|
URL={{ job_url }}.
|
||||||
|
|
||||||
@@ -164,7 +179,7 @@
|
|||||||
no_log: true
|
no_log: true
|
||||||
failed_when: graph_token.status not in [200]
|
failed_when: graph_token.status not in [200]
|
||||||
|
|
||||||
# --- Get recap from AWX and turn it into flat totals ---
|
# --- AWX recap (controller's tallies) ---
|
||||||
- name: Fetch play recap (playbook_on_stats)
|
- name: Fetch play recap (playbook_on_stats)
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
run_once: true
|
run_once: true
|
||||||
@@ -200,15 +215,30 @@
|
|||||||
OK={{ recap_ok | default(0) }},
|
OK={{ recap_ok | default(0) }},
|
||||||
Changed={{ recap_changed | default(0) }},
|
Changed={{ recap_changed | default(0) }},
|
||||||
Failed={{ recap_failed | default(0) }},
|
Failed={{ recap_failed | default(0) }},
|
||||||
Skipped={{ recap_skipped | default(0) }},
|
|
||||||
Unreachable={{ recap_unreach | default(0) }}
|
Unreachable={{ recap_unreach | default(0) }}
|
||||||
|
|
||||||
- name: Build final status from recap
|
# --- Aggregate per-host patch failures set in the first play ---
|
||||||
|
- name: Aggregate per-host patch failures
|
||||||
|
run_once: true
|
||||||
|
delegate_to: localhost
|
||||||
|
vars:
|
||||||
|
flags: "{{ ansible_play_hosts_all
|
||||||
|
| map('extract', hostvars, 'patch_failed_host')
|
||||||
|
| map('default', false) | list }}"
|
||||||
|
set_fact:
|
||||||
|
any_patch_failed: "{{ (flags | select('equalto', true) | list | length) > 0 }}"
|
||||||
|
|
||||||
|
- name: Build final status from recap + per-host flags
|
||||||
run_once: true
|
run_once: true
|
||||||
set_fact:
|
set_fact:
|
||||||
status_final: "{{ 'failed' if (recap_failed | int > 0 or recap_unreach | int > 0) else 'successful' }}"
|
status_final: >-
|
||||||
|
{{ 'failed'
|
||||||
|
if (any_patch_failed | default(false))
|
||||||
|
or (recap_failed | int > 0)
|
||||||
|
or (recap_unreach | int > 0)
|
||||||
|
else 'successful' }}
|
||||||
|
|
||||||
# --- Create list item (no block/rescue; use ignore_errors + diagnostics) ---
|
# --- Create list item (Graph) ---
|
||||||
- name: Create SharePoint list item (Graph)
|
- name: Create SharePoint list item (Graph)
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
run_once: true
|
run_once: true
|
||||||
@@ -230,6 +260,13 @@
|
|||||||
Notes: |-
|
Notes: |-
|
||||||
{{ summary_text }}
|
{{ summary_text }}
|
||||||
Recap: {{ hostvars['localhost'].recap_line }}
|
Recap: {{ hostvars['localhost'].recap_line }}
|
||||||
|
Failed hosts: {% set first=true -%}
|
||||||
|
{%- for h in ansible_play_hosts_all -%}
|
||||||
|
{%- if hostvars[h].patch_failed_host | default(false) -%}
|
||||||
|
{{ '' if first else ', ' }}{{ h }}{% set first=false -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{%- if first -%}None{%- endif -%}
|
||||||
register: sp_create
|
register: sp_create
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
no_log: true
|
no_log: true
|
||||||
|
|||||||
Reference in New Issue
Block a user