This commit is contained in:
2025-08-18 15:12:28 +02:00
parent 75f2bd520e
commit 85b84107c5

View File

@@ -4,23 +4,23 @@
gather_facts: no
vars:
# Root task folder: use '\\'
# If your task is in a folder, e.g. \Microsoft\Windows\WindowsUpdate\
# then set: '\\Microsoft\\Windows\\WindowsUpdate\\'
task_path: '\\'
task_path: '\\' # or '\\Microsoft\\Windows\\WindowsUpdate\\'
task_name: 'Patching-windows-task'
tasks:
- name: Start the SYSTEM patch task
- name: Start the SYSTEM patch task (schtasks)
ansible.windows.win_command: >
schtasks /Run /TN "{{ task_path }}{{ task_name }}"
register: start_task
changed_when: start_task.rc == 0 or
('SUCCESS' in (start_task.stdout | default('')))
failed_when: start_task.rc not in [0] and
('SUCCESS' not in (start_task.stdout | default('')))
failed_when: false
changed_when: >
(start_task is defined) and
(
(start_task.rc | default(999)) == 0
or ('SUCCESS' in (start_task.stdout | default('')))
)
- name: Poll task until it is Ready or Disabled
- name: Poll task until Ready/Disabled (PowerShell)
ansible.windows.win_powershell:
script: |
$ErrorActionPreference = 'Stop'
@@ -31,11 +31,11 @@
(Get-ScheduledTaskInfo -TaskPath $tp -TaskName $tn).State
register: task_state
failed_when: false
retries: 180 # up to 3 hours
retries: 180
delay: 60
until: (task_state.stdout | trim) in ['Ready','Disabled']
until: (task_state.stdout | default('') | trim) in ['Ready','Disabled']
- name: Reboot if needed
ansible.windows.win_reboot:
reboot_timeout: 3600
when: (task_state.stdout | trim) == 'Ready'
when: (task_state.stdout | default('') | trim) == 'Ready'