I have the following simple scheduler restart task for Windows and it works just fine, however I would like to have the option of maybe sometimes setting restart_morning_time
or restart_evening_time
to NULL
. What's the cleanest way to go about this? I tried having it as a list and also comma separated so I can pass as many restart_times
as I want and instead of having 2 variables, I would just have one called restart_times
(this would be ideal) but that just gives an error:
fatal: [windows-test-1]: FAILED! => {"changed": false, "msg": "trigger option 'start_boundary' must be in the format 'YYYY-MM-DDThh:mm:ss' format but was '2024-08-10T07:00:00 2024-08-10T19:00:00'"}
- name: Schedule restart for windows machine
community.windows.win_scheduled_task:
name: "Scheduled restart machine"
description: "This task restarts the machine at configured date && time"
actions:
- path: shutdown.exe
arguments: "/r /f /t 0"
triggers:
- type: "{{ trigger_type }}"
start_boundary: "{{ restart_morning_time }}"
- type: "{{ trigger_type }}"
start_boundary: "{{ restart_evening_time }}"
username: "SYSTEM"
run_level: highest
state: present
These are my vars I'm passing:
vars:
trigger_type: "daily" # Options could be 'daily', 'weekly', 'monthly'
restart_morning_time: "2024-08-10T07:00:00"
restart_evening_time: "2024-08-10T19:00:00"