From 75f2bd520ed11d2254d3f5424002db9e6da06bb0 Mon Sep 17 00:00:00 2001 From: "mhorak@totalservice.cz" Date: Mon, 18 Aug 2025 15:07:17 +0200 Subject: [PATCH] 9 --- patch-dc-controllers.yaml | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/patch-dc-controllers.yaml b/patch-dc-controllers.yaml index 0b6bb41..a4dc5fb 100644 --- a/patch-dc-controllers.yaml +++ b/patch-dc-controllers.yaml @@ -4,17 +4,21 @@ gather_facts: no vars: - task_path: "\" # e.g. "\" or "\Microsoft\Windows\WindowsUpdate\" - task_name: "Patching-windows-task" + # Root task folder: use '\\' + # If your task is in a folder, e.g. \Microsoft\Windows\WindowsUpdate\ + # then set: '\\Microsoft\\Windows\\WindowsUpdate\\' + task_path: '\\' + task_name: 'Patching-windows-task' tasks: - name: Start the SYSTEM patch task ansible.windows.win_command: > schtasks /Run /TN "{{ task_path }}{{ task_name }}" register: start_task - changed_when: start_task.rc == 0 + 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(''))) + ('SUCCESS' not in (start_task.stdout | default(''))) - name: Poll task until it is Ready or Disabled ansible.windows.win_powershell: @@ -23,23 +27,15 @@ Import-Module ScheduledTasks $tp = '{{ task_path }}' $tn = '{{ task_name }}' - # Confirm it exists (throws if not) $null = Get-ScheduledTask -TaskPath $tp -TaskName $tn - $state = (Get-ScheduledTaskInfo -TaskPath $tp -TaskName $tn).State - # Return plain text state for Ansible to parse - $state + (Get-ScheduledTaskInfo -TaskPath $tp -TaskName $tn).State register: task_state failed_when: false - retries: 3 # up to 3 hours + retries: 180 # up to 3 hours delay: 60 - until: task_state.stdout | trim in ['Ready','Disabled'] - - - name: Show last observed task state (debug) - ansible.builtin.debug: - msg: - - "Task '{{ task_path }}{{ task_name }}' final state: {{ task_state.stdout | trim }}" + until: (task_state.stdout | trim) in ['Ready','Disabled'] - name: Reboot if needed ansible.windows.win_reboot: reboot_timeout: 3600 - when: task_state.stdout | trim == 'Ready' \ No newline at end of file + when: (task_state.stdout | trim) == 'Ready' \ No newline at end of file