task
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user