On this page
win_scheduled_task - Manage scheduled tasks
New in version 2.0.
Synopsis
- Manage scheduled tasks
Options
parameter | required | default | choices | comments |
---|---|---|---|---|
arguments |
no |
Arguments to provide scheduled task action
aliases: argument
|
||
days_of_week |
no |
Days of the week to run a weekly task, not idempotent.
This option is required when frequence=weekly .
|
||
description |
no |
The description for the scheduled task
|
||
enabled |
no | True |
|
Enable/disable the task
|
executable |
no |
Command the scheduled task should execute.
This option is required when
state=true .
aliases: execute
|
||
frequency |
no |
|
The frequency of the command, not idempotent.
This option is required when state=true
|
|
name |
yes |
Name of the scheduled task
|
||
password
(added in 2.4)
|
no |
Password for the user account to run the scheduled task as. This is required for running a task without the user being logged in, excluding Windows built-in service accounts. This should be used for specifying credentials during initial task creation, and changing stored user credentials, as setting this value will cause the task to be recreated.
|
||
path |
no | \ |
Task folder in which this task will be stored - creates a non-existent path when state is present , and removes an empty path when state is absent
|
|
runlevel
(added in 2.4)
|
no | limited |
|
The level of user rights used to run the task
|
state |
yes |
|
State that the task should become
|
|
store_password
(added in 2.4)
|
no | True |
Store the password for the user running the task. If false , the task will only have access to local resources.
|
|
time |
no |
Time to execute scheduled task, not idempotent.
This option is required when state=true .
|
||
user |
no | DOMAIN\user |
User to run the scheduled task as; defaults to the current user
|
Examples
# Create a scheduled task to open a command prompt
- win_scheduled_task:
name: TaskName
description: open command prompt
executable: cmd
arguments: -opt1 -opt2
path: \example
time: 9am
frequency: daily
state: present
enabled: yes
user: SYSTEM
- name: Create a task to run a PowerShell script as NETWORK SERVICE at the highest user rights level
win_scheduled_task:
name: TaskName2
description: Run a PowerShell script
executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
arguments: -ExecutionPolicy Unrestricted -NonInteractive -File C:\TestDir\Test.ps1
time: 6pm
frequency: once
state: present
enabled: yes
user: NETWORK SERVICE
runlevel: highest
- name: Change the above task to run under a domain user account, storing credentials for the task
win_scheduled_task:
name: TaskName2
description: Run a PowerShell script
executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
arguments: -ExecutionPolicy Unrestricted -NonInteractive -File C:\TestDir\Test.ps1
time: 6pm
frequency: once
state: present
enabled: yes
user: DOMAIN\user
password: passwordGoesHere
runlevel: highest
- name: Change the above task again, choosing not to store the password for the account
win_scheduled_task:
name: TaskName2
description: Run a PowerShell script
executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
arguments: -ExecutionPolicy Unrestricted -NonInteractive -File C:\TestDir\Test.ps1
time: 6pm
frequency: once
state: present
enabled: yes
user: DOMAIN\user
runlevel: highest
store_password: no
Notes
Note
- This module requires Windows Server 2012 or later.
Status
This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.
For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.4/win_scheduled_task_module.html