ansible.builtin.win_scheduled_task (v2.4.2.0-1) — module

Manage scheduled tasks

| "added in version" 2.0 of ansible.builtin"

Authors: Peter Mounce

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.4.2.0.post1

Description

Manage scheduled tasks

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

    
name:
    description:
    - Name of the scheduled task
    required: true

path:
    default: \
    description:
    - Task folder in which this task will be stored - creates a non-existent path when
      C(state) is C(present), and removes an empty path when C(state) is C(absent)

time:
    description:
    - Time to execute scheduled task, not idempotent

user:
    default: DOMAIN\user
    description:
    - User to run the scheduled task as; defaults to the current user

state:
    choices:
    - present
    - absent
    description:
    - State that the task should become
    required: true

enabled:
    choices:
    - true
    - false
    default: true
    description:
    - Enable/disable the task

password:
    description:
    - 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.
    version_added: '2.4'
    version_added_collection: ansible.builtin

runlevel:
    choices:
    - limited
    - highest
    default: limited
    description:
    - The level of user rights used to run the task
    version_added: '2.4'
    version_added_collection: ansible.builtin

arguments:
    aliases:
    - argument
    description:
    - Arguments to provide scheduled task action

frequency:
    choices:
    - once
    - daily
    - weekly
    description:
    - The frequency of the command, not idempotent

executable:
    aliases:
    - execute
    description:
    - Command the scheduled task should execute

description:
    description:
    - The description for the scheduled task

days_of_week:
    description:
    - Days of the week to run a weekly task, not idempotent

store_password:
    default: true
    description:
    - Store the password for the user running the task.  If C(false), the task will only
      have access to local resources.
    version_added: '2.4'
    version_added_collection: ansible.builtin