summaryrefslogtreecommitdiff
path: root/lib/ansible/modules/windows/win_scheduled_task.py
blob: f0100f98dd5c9f2b797a1a11a8a2e501f67e11db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/python
# -*- coding: utf-8 -*-
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.

# this is a windows documentation stub.  actual code lives in the .ps1
# file of the same name

ANSIBLE_METADATA = {'metadata_version': '1.1',
                    'status': ['preview'],
                    'supported_by': 'community'}


DOCUMENTATION = r'''
---
module: win_scheduled_task
author: "Peter Mounce"
version_added: "2.0"
short_description: Manage scheduled tasks
description:
    - Manage scheduled tasks
notes:
    - This module requires Windows Server 2012 or later.
options:
  name:
    description:
      - Name of the scheduled task
    required: true
  description:
    description:
      - The description for the scheduled task
  enabled:
    description:
      - Enable/disable the task
    choices:
      - yes
      - no
    default: yes
  state:
    description:
      - State that the task should become
    required: true
    choices:
      - present
      - absent
  user:
    description:
      - User to run the scheduled task as; defaults to the current user
    default: DOMAIN\user
  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"
  runlevel:
    description:
      - The level of user rights used to run the task
    default: limited
    choices:
      - limited
      - highest
    version_added: "2.4"
  store_password:
    description:
      - Store the password for the user running the task.  If C(false), the task will only have access to local resources.
    default: true
    version_added: "2.4"
  executable:
    description:
      - Command the scheduled task should execute
    aliases: [ execute ]
  arguments:
    description:
      - Arguments to provide scheduled task action
    aliases: [ argument ]
  frequency:
    description:
      - The frequency of the command, not idempotent
    choices:
      - once
      - daily
      - weekly
  time:
    description:
      - Time to execute scheduled task, not idempotent
  days_of_week:
    description:
      - Days of the week to run a weekly task, not idempotent
  path:
    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)
    default: '\'
'''

EXAMPLES = r'''
# 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
'''