From 1ddd80a6f7eb751f5d0516f485ecefd43481e120 Mon Sep 17 00:00:00 2001 From: "mhorak@totalservice.cz" Date: Mon, 18 Aug 2025 14:43:19 +0200 Subject: [PATCH] 5 --- patch-dc-controllers.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/patch-dc-controllers.yaml b/patch-dc-controllers.yaml index 46019d7..122b8dc 100644 --- a/patch-dc-controllers.yaml +++ b/patch-dc-controllers.yaml @@ -9,15 +9,23 @@ script: | Start-ScheduledTask -TaskName 'Patching-windows-task' - - name: Wait until the task finishes + - name: Poll task until finished (Ready/Disabled) community.windows.win_scheduled_task_stat: name: "Patching-windows-task" register: patch_task - until: patch_task.task.state in ['Ready','Disabled'] # finished + failed_when: false # don't fail mid-poll if stat errors retries: 180 delay: 60 + until: > + (patch_task is not failed) + and (patch_task.task is defined) + and (patch_task.task.state | default('') in ['Ready','Disabled']) + + - name: Debug last observed task object (optional) + ansible.builtin.debug: + var: patch_task.task - name: Reboot if needed ansible.windows.win_reboot: reboot_timeout: 3600 - when: patch_task.task.state == 'Ready' \ No newline at end of file + when: patch_task.task is defined and patch_task.task.state == 'Ready' \ No newline at end of file