summaryrefslogtreecommitdiff
path: root/test/integration/targets/win_scheduled_task/tasks/tests.yml
blob: db62136b101c84832455ef08010f8f21ba9b7f67 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
- name: Remove potentially leftover scheduled task
  win_scheduled_task: &wst_absent
    name: Ansible Test
    state: absent


- name: Add scheduled task
  win_scheduled_task: &wst_present
    name: Ansible Test
    executable: dir.exe
    arguments: C:\Windows\Temp\
    frequency: once
    time: 5pm
    user: SYSTEM
  register: add_scheduled_task

- name: Test add_scheduled_task
  assert:
    that:
    - add_scheduled_task.changed == true
    - add_scheduled_task.exists == false


- name: Add scheduled task (again)
  win_scheduled_task: *wst_present
  register: add_scheduled_task_again

- name: Test add_scheduled_task_again (normal mode)
  assert:
    that:
    - add_scheduled_task_again.changed == false
    - add_scheduled_task_again.exists == true
  when: not in_check_mode

- name: Test add_scheduled_task_again (check-mode)
  assert:
    that:
    - add_scheduled_task_again.changed == true
    - add_scheduled_task_again.exists == false
  when: in_check_mode


# FIXME: The below tasks should not require all options
#        See: https://github.com/ansible/ansible/issues/19279
- name: Run tests for normal mode only (expects scheduled task)
  when: not in_check_mode
  block:

  - name: Disable scheduled task
    win_scheduled_task:
      <<: *wst_present
      enabled: no
    register: disable_scheduled_task

  - name: Test disable_scheduled_task
    assert:
      that:
      - disable_scheduled_task.changed == true
      - disable_scheduled_task.exists == true


  - name: Disable scheduled task (again)
    win_scheduled_task:
      <<: *wst_present
      enabled: no
    register: disable_scheduled_task_again

  - name: Test disable_scheduled_task_again
    assert:
      that:
      - disable_scheduled_task_again.changed == false
      - disable_scheduled_task_again.exists == true


  - name: Enable scheduled task
    win_scheduled_task:
      <<: *wst_present
      enabled: yes
    register: enable_scheduled_task

  - assert:
      that:
      - enable_scheduled_task.changed == true
      - enable_scheduled_task.exists == true

  - name: Enable scheduled task (again)
    win_scheduled_task:
      <<: *wst_present
      enabled: yes
    register: enable_scheduled_task_again

  - assert:
      that:
      - enable_scheduled_task_again.changed == false
      - enable_scheduled_task_again.exists == true


- name: Remove scheduled task
  win_scheduled_task: *wst_absent
  register: remove_scheduled_task

- name: Test remove_scheduled_task (normal mode)
  assert:
    that:
    - remove_scheduled_task.changed == true
    - remove_scheduled_task.exists == true
  when: not in_check_mode

- name: Test remove_scheduled_task (check-mode)
  assert:
    that:
    - remove_scheduled_task.changed == false
    - remove_scheduled_task.exists == false
  when: in_check_mode


- name: Remove scheduled task (again)
  win_scheduled_task: *wst_absent
  register: remove_scheduled_task_again

- name: Test remove_scheduled_task_again
  assert:
    that:
    - remove_scheduled_task_again.changed == false
    - remove_scheduled_task_again.exists == false


# Test scheduled task path creation and removal

- name: Remove potentially leftover new path task 1
  win_scheduled_task: &wstp1_absent
    name: Ansible Test New Path 1
    path: \non_existent_path\
    state: absent

- name: Remove potentially leftover new path task 2
  win_scheduled_task: &wstp2_absent
    name: Ansible Test New Path 2
    path: \non_existent_path\
    state: absent


- name: Add scheduled task new path 1
  win_scheduled_task: &wstp1_present
    name: Ansible Test New Path 1
    description: A test of functionality
    executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    arguments: -ExecutionPolicy Unrestricted -NonInteractive -File C:\TestDir\Test.ps1
    time: "9:45pm"
    path: \non_existent_path\
    frequency: once
    state: present
    enabled: yes
    user: SYSTEM
  register: add_scheduled_task_new_path_1

- name: Test add_scheduled_task_new_path_1
  assert:
    that:
    - add_scheduled_task_new_path_1.msg == 'Added new task Ansible Test New Path 1 and task path \\non_existent_path\\ created'


- name: Add scheduled task new path 2
  win_scheduled_task: &wstp2_present
    <<: *wstp1_present
    name: Ansible Test New Path 2
  register: add_scheduled_task_new_path_2

- name: Test add_scheduled_task_new_path_2 (normal mode)
  assert:
    that:
    - add_scheduled_task_new_path_2.msg == 'Added new task Ansible Test New Path 2'
  when: not in_check_mode

- name: Test add_scheduled_task_new_path_2 (check-mode)
  assert:
    that:
    - add_scheduled_task_new_path_2.msg == 'Added new task Ansible Test New Path 2 and task path \\non_existent_path\\ created'
  when: in_check_mode


- name: Remove scheduled task new path 2
  win_scheduled_task: *wstp2_absent
  register: remove_scheduled_task_new_path_2

- name: Test remove_scheduled_task_new_path_2 (normal mode)
  assert:
    that:
    - remove_scheduled_task_new_path_2.msg == 'Deleted task Ansible Test New Path 2'
  when: not in_check_mode

- name: Test remove_scheduled_task_new_path_2 (check-mode)
  assert:
    that:
    - remove_scheduled_task_new_path_2.msg == 'Task does not exist'
  when: in_check_mode


- name: Remove scheduled task new path 1
  win_scheduled_task: *wstp1_absent
  register: remove_scheduled_task_new_path_1

- name: Test remove_scheduled_task_new_path_1 (normal mode)
  assert:
    that:
    - remove_scheduled_task_new_path_1.msg == 'Deleted task Ansible Test New Path 1 and task path \\non_existent_path\\ removed'
  when: not in_check_mode

- name: Test remove_scheduled_task_new_path_1 (check-mode)
  assert:
    that:
    - remove_scheduled_task_new_path_1.msg == 'Task does not exist'
  when: in_check_mode


# Test scheduled task RunAs and RunLevel options

- name: Remove potentially leftover run options task 1
  win_scheduled_task: &wstr1_absent
    name: Ansible Test Run Options 1
    state: absent


- name: Add scheduled task run options 1
  win_scheduled_task: &wstr1_present
    name: Ansible Test Run Options 1
    description: A test of run options functionality
    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: SYSTEM
  register: add_scheduled_task_run_options_1

- name: Test add_scheduled_task_run_options_1
  assert:
    that:
    - add_scheduled_task_run_options_1.changed == true
    - add_scheduled_task_run_options_1.exists == false


- name: Execute run options tests for normal mode only (expects scheduled task)
  when: not in_check_mode
  block:

  - name: Change scheduled task run options user
    win_scheduled_task:
      <<: *wstr1_present
      user: NETWORK SERVICE
    register: change_scheduled_task_run_options_user

  - name: Test change_scheduled_task_run_options_user
    assert:
      that:
      - change_scheduled_task_run_options_user.changed == true
      - change_scheduled_task_run_options_user.exists == true


  - name: Change scheduled task run options user (again)
    win_scheduled_task:
      <<: *wstr1_present
      user: NETWORK SERVICE
    register: change_scheduled_task_run_options_user_again

  - name: Test change_scheduled_task_run_options_user_again
    assert:
      that:
      - change_scheduled_task_run_options_user_again.changed == false
      - change_scheduled_task_run_options_user_again.exists == true


  - name: Change scheduled task run options run level
    win_scheduled_task:
      <<: *wstr1_present
      user: NETWORK SERVICE
      runlevel: highest
    register: change_scheduled_task_run_options_runlevel

  - name: Test change_scheduled_task_run_options_runlevel
    assert:
      that:
      - change_scheduled_task_run_options_runlevel.changed == true
      - change_scheduled_task_run_options_runlevel.exists == true


  - name: Change scheduled task run options run level (again)
    win_scheduled_task:
      <<: *wstr1_present
      user: NETWORK SERVICE
      runlevel: highest
    register: change_scheduled_task_run_options_runlevel_again

  - name: Test change_scheduled_task_run_options_runlevel_again
    assert:
      that:
      - change_scheduled_task_run_options_runlevel_again.changed == false
      - change_scheduled_task_run_options_runlevel_again.exists == true


  # Should ignore change as account being tested is a built-in service account
  - name: Change scheduled task run options store password
    win_scheduled_task:
      <<: *wstr1_present
      user: NETWORK SERVICE
      runlevel: highest
      store_password: no
    register: change_scheduled_task_run_options_store_password

  - name: Test change_scheduled_task_run_options_store_password
    assert:
      that:
      - change_scheduled_task_run_options_store_password.changed == false
      - change_scheduled_task_run_options_store_password.exists == true


- name: Remove scheduled task run options 1
  win_scheduled_task: *wstr1_absent
  register: remove_scheduled_task_run_options_1

- name: Test remove_scheduled_task_run_options_1 (normal mode)
  assert:
    that:
    - remove_scheduled_task_run_options_1.changed == true
    - remove_scheduled_task_run_options_1.exists == true
  when: not in_check_mode

- name: Test remove_scheduled_task_run_options_1 (check-mode)
  assert:
    that:
    - remove_scheduled_task_run_options_1.changed == false
    - remove_scheduled_task_run_options_1.exists == false
  when: in_check_mode