This page is generated from the Chef Infra Client source code. To suggest a change, edit the windows_task.rb file and submit a pull request to the Chef Infra Client repository.
Use the windows_task resource to create, delete or run a Windows scheduled task.
New in Chef Infra Client 13.0.
The full syntax for all of the properties that are available to the windows_task resource is:
windows_task 'name' do
backup Integer, false # default value: 5
command String
cwd String
day String, Integer
description String
disallow_start_if_on_batteries true, false # default value: false
execution_time_limit String, Integer # default value: "PT72H (72 hours in ISO8601 duration format)"
force true, false # default value: false
frequency Symbol
frequency_modifier Integer, String # default value: 1
idle_time Integer
interactive_enabled true, false # default value: false
minutes_duration String, Integer
minutes_interval String, Integer
months String
password String
priority Integer # default value: 7
random_delay String, Integer
run_level Symbol # default value: :limited
start_day String # default value: The current date.
start_time String
start_when_available true, false # default value: false
stop_if_going_on_batteries true, false # default value: false
task_name String # default value: 'name' unless specified
user String # default value: The localized SYSTEM user for the node.
action Symbol # defaults to :create if not specified
endwhere:
windows_task is the resource.name is the name given to the resource block.action identifies which steps Chef Infra Client will take to bring the node into the desired state.backup, command, cwd, day, description, disallow_start_if_on_batteries, execution_time_limit, force, frequency, frequency_modifier, idle_time, interactive_enabled, minutes_duration, minutes_interval, months, password, priority, random_delay, run_level, start_day, start_time, start_when_available, stop_if_going_on_batteries, task_name, and user are the properties available to this resource.The windows_task resource has the following actions:
:create:delete:disable:enable:end:nothing:runThe windows_task resource has the following properties:
backup 5 Number of backups to keep of the task when modified/deleted. Set to false to disable backups.
New in Chef Infra Client 17.0
command The command to be executed by the windows scheduled task.
cwd The directory the task will be run from.
day The day(s) on which the task runs.
frequency to :monthly or :weekly.:weekly are MON-SUN or *.:monthly are 1-31, MON-SUN, and LASTDAY.MON-SUN or LASTDAY if you are setting frequency_modifier as “FIRST, SECOND, THIRD etc.” else use 1-31.1, 2, 3 or MON, WED, FRI.description The task description.
New in Chef Client 14.7
disallow_start_if_on_batteries false Disallow start of the task if the system is running on battery power.
New in Chef Client 14.4
execution_time_limit PT72H (72 hours in ISO8601 duration format) The maximum time the task will run. This field accepts either seconds or an ISO8601 duration value.
force false When used with create, will update the task.
frequency :daily, :hourly, :minute, :monthly, :none, :on_idle, :on_logon, :once, :onstart, :weekly The frequency with which to run the task.
Note
This property is required in Chef Infra Client 14.1 or later.
Note
The :once value requires the start_time property to be set.
frequency_modifier 1
:minute valid values are 1 to 1439:hourly valid values are 1 to 23:daily valid values are 1 to 365:weekly valid values are 1 to 52:monthly valid values are ('FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST') OR 1-12. second week of the month use frequency_modifier value as SECOND. Multiple values for weeks of the month should be comma separated e.g. "FIRST, THIRD, LAST".idle_time For :on_idle frequency, the time (in minutes) without user activity that must pass to trigger the task, from 1 - 999.
interactive_enabled false Allow task to run interactively or non-interactively. Requires user and password to also be set.
minutes_duration minutes_interval months The Months of the year on which the task runs, such as: JAN, FEB or *. Multiple months should be comma delimited. e.g. Jan, Feb, Mar, Dec.
password The user’s password. The user property must be set if using this property.
priority 7 Use to set Priority Levels range from 0 to 10.
random_delay Delays the task up to a given time (in seconds).
run_level :limited Allowed Values: :highest, :limited Run with :limited or :highest privileges.
start_day The current date. Specifies the first date on which the task runs in MM/DD/YYYY format.
start_time Specifies the start time to run the task, in HH:mm format.
start_when_available false To start the task at any time after its scheduled time has passed.
New in Chef Client 14.15
stop_if_going_on_batteries false Scheduled task option when system is switching on battery.
New in Chef Client 14.4
task_name The resource block's name An optional property to set the task name if it differs from the resource block’s name. Example: Task Name or /Task Name
user The localized SYSTEM user for the node. The user to run the task as.
Chef resources include common properties, notifications, and resource guards.
The following properties are common to every resource:
compile_timeRuby Type: true, false | Default Value: false
Control the phase during which the resource is run on the node. Set to true to run while the resource collection is being built (the compile phase). Set to false to run while Chef Infra Client is configuring the node (the converge phase).
ignore_failureRuby Type: true, false, :quiet | Default Value: false
Continue running a recipe if a resource fails for any reason. :quiet will not display the full stack trace and the recipe will continue to run if a resource fails.
retriesRuby Type: Integer | Default Value: 0
The number of attempts to catch exceptions and retry the resource.
retry_delayRuby Type: Integer | Default Value: 2
The delay in seconds between retry attempts.
sensitiveRuby Type: true, false | Default Value: false
Ensure that sensitive resource data is not logged by Chef Infra Client.
notifies Ruby Type: Symbol, 'Chef::Resource[String]'
A resource may notify another resource to take action when its state changes. Specify a 'resource[name]', the :action that resource should take, and then the :timer for that action. A resource may notify more than one resource; use a notifies statement for each resource to be notified.
If the referenced resource does not exist, an error is raised. In contrast, subscribes will not fail if the source resource is not found.
A timer specifies the point during a Chef Infra Client run at which a notification is run. The following timers are available:
:beforeSpecifies that the action on a notified resource should be run before processing the resource block in which the notification is located.
:delayedDefault. Specifies that a notification should be queued up, and then executed at the end of a Chef Infra Client run.
:immediate, :immediately
Specifies that a notification should be run immediately, per resource notified.
The syntax for notifies is:
notifies :action, 'resource[name]', :timer
subscribes Ruby Type: Symbol, 'Chef::Resource[String]'
A resource may listen to another resource, and then take action if the state of the resource being listened to changes. Specify a 'resource[name]', the :action to be taken, and then the :timer for that action.
Note that subscribes does not apply the specified action to the resource that it listens to - for example:
file '/etc/nginx/ssl/example.crt' do
mode '0600'
owner 'root'
end
service 'nginx' do
subscribes :reload, 'file[/etc/nginx/ssl/example.crt]', :immediately
end
In this case the subscribes property reloads the nginx service whenever its certificate file, located under /etc/nginx/ssl/example.crt, is updated. subscribes does not make any changes to the certificate file itself, it merely listens for a change to the file, and executes the :reload action for its resource (in this example nginx) when a change is detected.
If the other resource does not exist, the subscription will not raise an error. Contrast this with the stricter semantics of notifies, which will raise an error if the other resource does not exist.
A timer specifies the point during a Chef Infra Client run at which a notification is run. The following timers are available:
:beforeSpecifies that the action on a notified resource should be run before processing the resource block in which the notification is located.
:delayedDefault. Specifies that a notification should be queued up, and then executed at the end of a Chef Infra Client run.
:immediate, :immediately
Specifies that a notification should be run immediately, per resource notified.
The syntax for subscribes is:
subscribes :action, 'resource[name]', :timer
A guard property can be used to evaluate the state of a node during the execution phase of a Chef Infra Client run. Based on the results of this evaluation, a guard property is then used to tell Chef Infra Client if it should continue executing a resource. A guard property accepts either a string value or a Ruby block value:
0, the guard is applied. If the command returns any other value, then the guard property is not applied. String guards in a powershell_script run Windows PowerShell commands and may return true in addition to 0.true or false. If the block returns true, the guard property is applied. If the block returns false, the guard property is not applied.A guard property is useful for ensuring that a resource is idempotent by allowing that resource to test for the desired state as it is being executed, and then if the desired state is present, for Chef Infra Client to do nothing.
PropertiesThe following properties can be used to define a guard that is evaluated during the execution phase of a Chef Infra Client run:
not_ifPrevent a resource from executing when the condition returns true.
only_ifAllow a resource to execute only if the condition returns true.
The following examples demonstrate various approaches for using the windows_task resource in recipes:
Create a scheduled task to run every 15 minutes as the Administrator user:
windows_task 'chef-client' do
user 'Administrator'
password 'password'
command 'chef-client'
run_level :highest
frequency :minute
frequency_modifier 15
end
Create a scheduled task to run every 2 days:
windows_task 'chef-client' do
command 'chef-client'
run_level :highest
frequency :daily
frequency_modifier 2
end
Create a scheduled task to run on specific days of the week:
windows_task 'chef-client' do
command 'chef-client'
run_level :highest
frequency :weekly
day 'Mon, Thu'
end
Create a scheduled task to run only once:
windows_task 'chef-client' do
command 'chef-client'
run_level :highest
frequency :once
start_time '16:10'
end
Create a scheduled task to run on current day every 3 weeks and delay upto 1 min:
windows_task 'chef-client' do
command 'chef-client'
run_level :highest
frequency :weekly
frequency_modifier 3
random_delay '60'
end
Create a scheduled task to run weekly starting on Dec 28th 2018:
windows_task 'chef-client 8' do
command 'chef-client'
run_level :highest
frequency :weekly
start_day '12/28/2018'
end
Create a scheduled task to run every Monday, Friday every 2 weeks:
windows_task 'chef-client' do
command 'chef-client'
run_level :highest
frequency :weekly
frequency_modifier 2
day 'Mon, Fri'
end
Create a scheduled task to run when computer is idle with idle duration 20 min:
windows_task 'chef-client' do
command 'chef-client'
run_level :highest
frequency :on_idle
idle_time 20
end
Delete a task named “old task”:
windows_task 'old task' do
action :delete
end
Enable a task named “chef-client”:
windows_task 'chef-client' do
action :enable
end
Disable a task named “ProgramDataUpdater” with TaskPath “\Microsoft\Windows\Application Experience\ProgramDataUpdater”
windows_task '\Microsoft\Windows\Application Experience\ProgramDataUpdater' do
action :disable
end
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/resources/windows_task/