summaryrefslogtreecommitdiff
path: root/test/integration/targets/win_iis_webapppool/tasks/tests.yml
blob: 3391b51511e80c6d9e1517ac9b01290a24a419df (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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
---
- name: create default pool check
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: started
  register: create_default_check
  check_mode: yes

- name: get actual of create default pool check
  win_command: powershell.exe "Import-Module WebAdministration; Get-Item -Path IIS:\AppPools\{{test_iis_webapppool_name}}"
  register: create_default_actual_check
  failed_when: False

- name: assert create default pool check
  assert:
    that:
    - create_default_check is changed
    - create_default_actual_check.rc == 1

- name: create default pool
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
  register: create_default

- name: get actual of create default pool
  win_command: powershell.exe "Import-Module WebAdministration; Get-Item -Path IIS:\AppPools\{{test_iis_webapppool_name}}"
  register: create_default_actual
  failed_when: False

- name: assert create default pool
  assert:
    that:
    - create_default is changed
    - create_default.info.attributes.name == test_iis_webapppool_name
    - create_default.info.attributes.startMode == 'OnDemand'
    - create_default.info.attributes.state == 'Started'
    - create_default_actual.rc == 0

- name: change attributes of pool check
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes:
      managedPipelineMode: 1 # Using an enum value
      cpu.limit: 95 # Nested values
      processModel.identityType: LocalSystem # Using an enum name
      processModel.loadUserProfile: True
  register: change_pool_attributes_check
  check_mode: yes

- name: assert change attributes of pool check
  assert:
    that:
    - change_pool_attributes_check is changed
    - change_pool_attributes_check.info == create_default.info

- name: change attributes of pool
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes:
      managedPipelineMode: 1 # Using an enum value
      cpu.limit: 95 # Nested values
      processModel.identityType: LocalSystem # Using an enum name
      processModel.loadUserProfile: True
    test: True
  register: change_pool_attributes

- name: assert change attributes of pool
  assert:
    that:
    - change_pool_attributes is changed
    - change_pool_attributes.info.attributes.managedPipelineMode == 'Classic'
    - change_pool_attributes.info.cpu.limit == 95
    - change_pool_attributes.info.processModel.identityType == 'LocalSystem'
    - change_pool_attributes.info.processModel.loadUserProfile == True

- name: change attributes of pool again
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes:
      managedPipelineMode: 1 # Using an enum value
      cpu.limit: 95 # Nested values
      processModel.identityType: LocalSystem # Using an enum name
      processModel.loadUserProfile: True
  register: change_pool_attributes_again

- name: assert change attributes of pool again
  assert:
    that:
    - change_pool_attributes_again is not changed
    - change_pool_attributes_again.info == change_pool_attributes.info

- name: change attributes of pool (old style) check
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes: "managedPipelineMode:0|startMode:OnDemand|cpu.limit:0|processModel.identityType:NetworkService"
  register: change_pool_attributes_deprecated_check
  check_mode: yes

- name: assert change attributes of pool (old style) check
  assert:
    that:
    - change_pool_attributes_deprecated_check is changed
    - change_pool_attributes_deprecated_check.info == change_pool_attributes_again.info

- name: change attributes of pool (old style)
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes: "managedPipelineMode:0|startMode:OnDemand|cpu.limit:10|processModel.identityType:NetworkService"
  register: change_pool_attributes_deprecated

- name: assert change attributes of pool (old style)
  assert:
    that:
    - change_pool_attributes_deprecated is changed
    - change_pool_attributes_deprecated.info.attributes.managedPipelineMode == 'Integrated'
    - change_pool_attributes_deprecated.info.attributes.startMode == 'OnDemand'
    - change_pool_attributes_deprecated.info.cpu.limit == 10
    - change_pool_attributes_deprecated.info.processModel.identityType == 'NetworkService'

- name: change attributes of pool (old style) again
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes: "managedPipelineMode:0|startMode:OnDemand|cpu.limit:10|processModel.identityType:NetworkService"
  register: change_pool_attributes_deprecated_again

- name: assert change attributes of pool (old style) again
  assert:
    that:
    - change_pool_attributes_deprecated_again is not changed
    - change_pool_attributes_deprecated_again.info == change_pool_attributes_deprecated.info

- name: change more complex variables check
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes:
      queueLength: 500
      recycling.periodicRestart.requests: 10 # Deeply nested attribute
      recycling.periodicRestart.time: "00:00:05:00.000000" # Timespan with string
      processModel.pingResponseTime: "00:03:00" # Timespan without days or milliseconds
  register: change_complex_attributes_check
  check_mode: yes

- name: assert change more complex variables check
  assert:
    that:
    - change_complex_attributes_check is changed
    - change_complex_attributes_check.info == change_pool_attributes_deprecated_again.info

- name: change more complex variables
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes:
      queueLength: 500
      recycling.periodicRestart.requests: 10 # Deeply nested attribute
      recycling.periodicRestart.time: "00:00:05:00.000000" # Timespan with string
      processModel.pingResponseTime: "00:03:00" # Timespan without days or milliseconds
  register: change_complex_attributes

- name: assert change more complex variables
  assert:
    that:
    - change_complex_attributes is changed
    - change_complex_attributes.info.attributes.queueLength == 500
    - change_complex_attributes.info.recycling.periodicRestart.requests == 10
    - change_complex_attributes.info.recycling.periodicRestart.time.TotalSeconds == 300
    - change_complex_attributes.info.processModel.pingResponseTime.TotalSeconds == 180

- name: change more complex variables again
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes:
      queueLength: 500
      recycling.periodicRestart.requests: 10 # Deeply nested attribute
      recycling.periodicRestart.time: "00:00:05:00.000000" # Timespan with string
      processModel.pingResponseTime: "00:03:00" # Timespan without days or milliseconds
  register: change_complex_attributes_again

- name: assert change more complex variables again
  assert:
    that:
    - change_complex_attributes_again is not changed
    - change_complex_attributes_again.info == change_complex_attributes.info

- name: stop web pool check
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: stopped
  register: stop_pool_check
  check_mode: yes

- name: get actual status of pool check
  win_command: powershell.exe "Import-Module WebAdministration; (Get-Item -Path IIS:\AppPools\{{test_iis_webapppool_name}}).state"
  register: stop_pool_actual_check

- name: assert stop web pool check
  assert:
    that:
    - stop_pool_check is changed
    - stop_pool_actual_check.stdout == 'Started\r\n'

- name: stop web pool
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: stopped
  register: stop_pool

- name: get actual status of pool
  win_command: powershell.exe "Import-Module WebAdministration; (Get-Item -Path IIS:\AppPools\{{test_iis_webapppool_name}}).state"
  register: stop_pool_actual

- name: assert stop web pool
  assert:
    that:
    - stop_pool is changed
    - stop_pool_actual.stdout == 'Stopped\r\n'

- name: stop web pool again
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: stopped
  register: stop_pool_again

- name: get actual status of pool again
  win_command: powershell.exe "Import-Module WebAdministration; (Get-Item -Path IIS:\AppPools\{{test_iis_webapppool_name}}).state"
  register: stop_pool_actual_again

- name: assert stop web pool again
  assert:
    that:
    - stop_pool_again is not changed
    - stop_pool_actual_again.stdout == 'Stopped\r\n'

- name: start web pool check
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: started
  register: start_pool_check
  check_mode: yes

- name: get actual status of pool check
  win_command: powershell.exe "Import-Module WebAdministration; (Get-Item -Path IIS:\AppPools\{{test_iis_webapppool_name}}).state"
  register: start_pool_actual_check

- name: assert start web pool check
  assert:
    that:
    - start_pool_check is changed
    - start_pool_actual_check.stdout == 'Stopped\r\n'

- name: start web pool
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: started
  register: start_pool

- name: get actual status of pool
  win_command: powershell.exe "Import-Module WebAdministration; (Get-Item -Path IIS:\AppPools\{{test_iis_webapppool_name}}).state"
  register: start_pool_actual

- name: assert start web pool
  assert:
    that:
    - start_pool is changed
    - start_pool_actual.stdout == 'Started\r\n'

- name: start web pool again
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: started
  register: start_pool_again

- name: get actual status of pool again
  win_command: powershell.exe "Import-Module WebAdministration; (Get-Item -Path IIS:\AppPools\{{test_iis_webapppool_name}}).state"
  register: start_pool_actual_again

- name: assert start web pool again
  assert:
    that:
    - start_pool_again is not changed
    - start_pool_actual_again.stdout == 'Started\r\n'

- name: restart web pool
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: restarted
  register: restart_pool

- name: get actual status of pool
  win_command: powershell.exe "Import-Module WebAdministration; (Get-Item -Path IIS:\AppPools\{{test_iis_webapppool_name}}).state"
  register: restart_pool_actual

- name: assert restart web pool
  assert:
    that:
    - restart_pool is changed
    - restart_pool_actual.stdout == 'Started\r\n'

- name: stop pool before restart on stop test
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: stopped

- name: restart from stopped web pool check
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: restarted
  register: restart_from_stop_pool_check
  check_mode: yes

- name: get actual status of pool check
  win_command: powershell.exe "Import-Module WebAdministration; (Get-Item -Path IIS:\AppPools\{{test_iis_webapppool_name}}).state"
  register: restart_from_stop_pool_actual_check

- name: assert restart from stopped web pool check
  assert:
    that:
    - restart_from_stop_pool_check is changed
    - restart_from_stop_pool_actual_check.stdout == 'Stopped\r\n'

- name: restart from stopped web pool
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: restarted
  register: restart_from_stop_pool

- name: get actual status of pool
  win_command: powershell.exe "Import-Module WebAdministration; (Get-Item -Path IIS:\AppPools\{{test_iis_webapppool_name}}).state"
  register: restart_from_stop_pool_actual

- name: assert restart from stopped web pool
  assert:
    that:
    - restart_from_stop_pool is changed
    - restart_from_stop_pool_actual.stdout == 'Started\r\n'

- name: set web pool attribute that is a collection (check mode)
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes:
      recycling.periodicRestart.schedule: "00:10:00,10:10:00"
  register: collection_change_check
  check_mode: yes

- name: get result of set web pool attribute that is a collection (check mode)
  win_shell: |
    Import-Module WebAdministration
    (Get-ItemProperty -Path "IIS:\AppPools\{{test_iis_webapppool_name}}" -Name recycling.periodicRestart.schedule).Collection | ForEach-Object { $_.value.ToString() }
  register: collection_change_result_check

- name: assert results of set web pool attribute that is a collection (check mode)
  assert:
    that:
    - collection_change_check is changed
    - collection_change_result_check.stdout == ""

- name: set web pool attribute that is a collection
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes:
      recycling.periodicRestart.schedule: "00:10:00,10:10:00"
  register: collection_change

- name: get result of set web pool attribute that is a collection
  win_shell: |
    Import-Module WebAdministration
    (Get-ItemProperty -Path "IIS:\AppPools\{{test_iis_webapppool_name}}" -Name recycling.periodicRestart.schedule).Collection | ForEach-Object { $_.value.ToString() }
  register: collection_change_result

- name: assert results of set web pool attribute that is a collection
  assert:
    that:
    - collection_change is changed
    - collection_change_result.stdout_lines == [ "00:10:00", "10:10:00" ]

- name: set web pool attribute that is a collection (idempotent)
  win_iis_webapppool:
    name: '{{test_iis_webapppool_name}}'
    state: present
    attributes:
      recycling.periodicRestart.schedule: [ "00:10:00", "10:10:00" ]
  register: collection_change_again

- name: assert results of set web pool attribute that is a collection (idempotent)
  assert:
    that:
    - collection_change_again is not changed

# The following tests are only for IIS versions 8.0 or newer
- block:
  - name: delete test pool
    win_iis_webapppool:
      name: '{{test_iis_webapppool_name}}'
      state: absent

  - name: create test pool
    win_iis_webapppool:
      name: '{{test_iis_webapppool_name}}'
      state: present
    register: iis_attributes_blank

  - name: change attributes for newer IIS version check
    win_iis_webapppool:
      name: '{{test_iis_webapppool_name}}'
      state: present
      attributes:
        startMode: AlwaysRunning
        processModel.identityType: 3
        processModel.userName: '{{ansible_user}}'
        processModel.password: '{{ansible_password}}'
    register: iis_attributes_new_check
    check_mode: yes
  
  - name: assert change attributes for newer IIS version check
    assert:
      that:
      - iis_attributes_new_check is changed
      - iis_attributes_new_check.info == iis_attributes_blank.info

  - name: change attributes for newer IIS version
    win_iis_webapppool:
      name: '{{test_iis_webapppool_name}}'
      state: present
      attributes:
        startMode: AlwaysRunning
        processModel.identityType: 3
        processModel.userName: '{{ansible_user}}'
        processModel.password: '{{ansible_password}}'
    register: iis_attributes_new
  
  - name: assert change attributes for newer IIS version
    assert:
      that:
      - iis_attributes_new is changed
      - iis_attributes_new.info.attributes.startMode == 'AlwaysRunning'
      - iis_attributes_new.info.processModel.identityType == 'SpecificUser'
      - iis_attributes_new.info.processModel.userName == ansible_user
      - iis_attributes_new.info.processModel.password == ansible_password

  - name: change attributes for newer IIS version again
    win_iis_webapppool:
      name: '{{test_iis_webapppool_name}}'
      state: present
      attributes:
        startMode: AlwaysRunning
        processModel.identityType: 3
        processModel.userName: '{{ansible_user}}'
        processModel.password: '{{ansible_password}}'
    register: iis_attributes_new_again
  
  - name: assert change attributes for newer IIS version again
    assert:
      that:
      - iis_attributes_new_again is not changed
      - iis_attributes_new_again.info == iis_attributes_new.info

  when: iis_version.win_file_version.file_major_part|int > 7