From e2b2881b381c9838e1a737ffca64382e9c540ca5 Mon Sep 17 00:00:00 2001 From: "mhorak@totalservice.cz" Date: Tue, 19 Aug 2025 17:06:46 +0200 Subject: [PATCH] task --- patch-dc-controllers.yaml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/patch-dc-controllers.yaml b/patch-dc-controllers.yaml index bb08852..fda607d 100644 --- a/patch-dc-controllers.yaml +++ b/patch-dc-controllers.yaml @@ -27,24 +27,29 @@ (start_task.rc | default(1)) == 0 or ('SUCCESS' in (start_task.stdout | default(''))) - - name: Poll until Ready/Disabled with success + - name: Poll until Ready/Disabled with LastTaskResult 0 ansible.windows.win_powershell: script: | $ErrorActionPreference = 'Stop' Import-Module ScheduledTasks $tp='{{ task_path }}'; $tn='{{ task_name }}' $i = Get-ScheduledTaskInfo -TaskPath $tp -TaskName $tn - [PSCustomObject]@{ State=$i.State; LastTaskResult=$i.LastTaskResult } | ConvertTo-Json -Compress + [PSCustomObject]@{ State=$i.State; LastTaskResult=$i.LastTaskResult; LastRunTime=$i.LastRunTime } | + ConvertTo-Json -Compress register: task_info failed_when: false retries: "{{ finish_retries }}" delay: "{{ poll_delay }}" until: > - (task_info.stdout | default('') | length > 0) - and ((task_info.stdout | from_json).State in ['Ready','Disabled']) - and (((task_info.stdout | from_json).LastTaskResult | int) == 0) + ((task_info.stdout | default('')) | length > 0) + and (((task_info.stdout | default('{}')) | from_json).State in ['Ready','Disabled']) + and ((((task_info.stdout | default('{}')) | from_json).LastTaskResult | int) in [0,3010]) - - name: Reboot if needed + - name: Parse task info safely + ansible.builtin.set_fact: + task_info_parsed: "{{ (task_info.stdout | default('{}')) | from_json }}" + + - name: Reboot if needed (state Ready) ansible.windows.win_reboot: reboot_timeout: 5400 - when: (task_info.stdout | from_json).State == 'Ready' + when: task_info_parsed.State == 'Ready'