| 1 |
# This file is part of Ansible |
| 2 |
|
| 3 |
# Copyright: (c) 2020, Brian Scholer <@briantist> |
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
--- |
| 6 |
- name: Create a simple configuration (check) |
| 7 |
win_pssession_configuration: |
| 8 |
name: "{{ config_name }}" |
| 9 |
description: "{{ config_description }}" |
| 10 |
modules_to_import: Microsoft.PowerShell.Utility |
| 11 |
register: status |
| 12 |
check_mode: yes |
| 13 |
|
| 14 |
- name: Check for changed status |
| 15 |
assert: |
| 16 |
that: status is changed |
| 17 |
quiet: yes |
| 18 |
|
| 19 |
- name: Create a simple configuration |
| 20 |
win_pssession_configuration: |
| 21 |
name: "{{ config_name }}" |
| 22 |
description: "{{ config_description }}" |
| 23 |
modules_to_import: Microsoft.PowerShell.Utility |
| 24 |
register: status |
| 25 |
|
| 26 |
- name: Check for changed status |
| 27 |
assert: |
| 28 |
that: status is changed |
| 29 |
quiet: yes |
| 30 |
|
| 31 |
- name: Create a simple configuration again (check) |
| 32 |
win_pssession_configuration: |
| 33 |
name: "{{ config_name }}" |
| 34 |
description: "{{ config_description }}" |
| 35 |
modules_to_import: Microsoft.PowerShell.Utility |
| 36 |
register: status |
| 37 |
check_mode: yes |
| 38 |
|
| 39 |
- name: Check for unchanged status |
| 40 |
assert: |
| 41 |
that: status is not changed |
| 42 |
quiet: yes |
| 43 |
|
| 44 |
- name: Create a simple configuration again |
| 45 |
win_pssession_configuration: |
| 46 |
name: "{{ config_name }}" |
| 47 |
description: "{{ config_description }}" |
| 48 |
modules_to_import: Microsoft.PowerShell.Utility |
| 49 |
register: status |
| 50 |
|
| 51 |
- name: Check for unchanged status |
| 52 |
assert: |
| 53 |
that: status is not changed |
| 54 |
quiet: yes |
| 55 |
|
| 56 |
####### |
| 57 |
|
| 58 |
- name: Try to disable polling (failure expected) |
| 59 |
win_pssession_configuration: |
| 60 |
name: "{{ config_name }}" |
| 61 |
description: "{{ config_description }}~~~~" |
| 62 |
modules_to_import: Microsoft.PowerShell.Utility |
| 63 |
async_timeout: 500 |
| 64 |
async_poll: 0 |
| 65 |
register: status |
| 66 |
ignore_errors: yes |
| 67 |
|
| 68 |
- name: Ensure it failed |
| 69 |
assert: |
| 70 |
that: |
| 71 |
- status is failed |
| 72 |
- status.msg is search('async_poll') |
| 73 |
quiet: yes |
| 74 |
|
| 75 |
- name: Try it with the keywords (failure expected) |
| 76 |
win_pssession_configuration: |
| 77 |
name: "{{ config_name }}" |
| 78 |
description: "{{ config_description }}" |
| 79 |
modules_to_import: Microsoft.PowerShell.Utility |
| 80 |
async: 500 |
| 81 |
poll: 2 |
| 82 |
register: status |
| 83 |
ignore_errors: yes |
| 84 |
|
| 85 |
- name: Check for expected failire |
| 86 |
assert: |
| 87 |
that: status is failed |
| 88 |
quiet: yes |
| 89 |
|
| 90 |
####### |
| 91 |
|
| 92 |
- name: Try to set a parameter that's only available in PowerShell 5+ (check) |
| 93 |
win_pssession_configuration: |
| 94 |
name: "{{ config_name }}" |
| 95 |
description: "{{ config_description }}" |
| 96 |
mount_user_drive: True |
| 97 |
register: status |
| 98 |
check_mode: yes |
| 99 |
ignore_errors: yes |
| 100 |
|
| 101 |
- name: Check for version-based status |
| 102 |
assert: |
| 103 |
that: (status is failed) == (ansible_powershell_version < 5) |
| 104 |
quiet: yes |
| 105 |
|
| 106 |
####### |
| 107 |
# Incomplete tests for future enhancement of waiting for connections before making changes |
| 108 |
|
| 109 |
# - name: Start a 45 second WinRM connection |
| 110 |
# ansible.windows.win_shell: | |
| 111 |
# Invoke-Command -ComputerName . -ScriptBlock { Start-Sleep -Seconds 45 } -AsJob |
| 112 |
|
| 113 |
# - name: Make a change with a 10 second fail on timeout (failure expected) |
| 114 |
# win_pssession_configuration: |
| 115 |
# name: "{{ config_name }}" |
| 116 |
# description: "{{ config_description }}" |
| 117 |
# mount_user_drive: False |
| 118 |
# existing_connection_timeout_seconds: 10 |
| 119 |
# existing_connection_timeout_action: fail |
| 120 |
# register: status |
| 121 |
# ignore_errors: yes |
| 122 |
|
| 123 |
# - name: Check for failed status |
| 124 |
# assert: |
| 125 |
# that: status is failed |
| 126 |
# quiet: yes |
| 127 |
|
| 128 |
# - name: Start a 25 second WinRM connection |
| 129 |
# ansible.windows.win_shell: | |
| 130 |
# Invoke-Command -ComputerName . -ScriptBlock { Start-Sleep -Seconds 25 } -AsJob |
| 131 |
|
| 132 |
# - name: Make a change with a 45 second fail on timeout (success expected) |
| 133 |
# win_pssession_configuration: |
| 134 |
# name: "{{ config_name }}" |
| 135 |
# description: "{{ config_description }}" |
| 136 |
# mount_user_drive: False |
| 137 |
# existing_connection_timeout_seconds: 10 |
| 138 |
# existing_connection_timeout_action: fail |
| 139 |
# register: status |
| 140 |
|
| 141 |
# - name: Check for changed status |
| 142 |
# assert: |
| 143 |
# that: status is changed |
| 144 |
# quiet: yes |
| 145 |
|
| 146 |
####### |
| 147 |
- name: Omit a field that doesn't matter (check) |
| 148 |
win_pssession_configuration: |
| 149 |
name: "{{ config_name }}" |
| 150 |
# description: "{{ config_description }}" # intentionally omitted |
| 151 |
modules_to_import: Microsoft.PowerShell.Utility |
| 152 |
register: status |
| 153 |
check_mode: yes |
| 154 |
|
| 155 |
- name: Check for unchanged status |
| 156 |
assert: |
| 157 |
that: status is not changed |
| 158 |
quiet: yes |
| 159 |
|
| 160 |
- name: Omit a field that doesn't matter |
| 161 |
win_pssession_configuration: |
| 162 |
name: "{{ config_name }}" |
| 163 |
# description: "{{ config_description }}" # intentionally omitted |
| 164 |
modules_to_import: Microsoft.PowerShell.Utility |
| 165 |
register: status |
| 166 |
|
| 167 |
- name: Check for unchanged status |
| 168 |
assert: |
| 169 |
that: status is not changed |
| 170 |
quiet: yes |
| 171 |
|
| 172 |
####### |
| 173 |
|
| 174 |
- name: Omit a field that doesn't matter by default but does explicitly (check) |
| 175 |
win_pssession_configuration: |
| 176 |
name: "{{ config_name }}" |
| 177 |
# description: "{{ config_description }}" # intentionally omitted |
| 178 |
modules_to_import: Microsoft.PowerShell.Utility |
| 179 |
lenient_config_fields: |
| 180 |
- guid |
| 181 |
- author |
| 182 |
register: status |
| 183 |
check_mode: yes |
| 184 |
|
| 185 |
- name: Check for changed status |
| 186 |
assert: |
| 187 |
that: status is changed |
| 188 |
quiet: yes |
| 189 |
|
| 190 |
- name: Omit a field that doesn't matter by default but does explicitly |
| 191 |
win_pssession_configuration: |
| 192 |
name: "{{ config_name }}" |
| 193 |
# description: "{{ config_description }}" # intentionally omitted |
| 194 |
modules_to_import: Microsoft.PowerShell.Utility |
| 195 |
lenient_config_fields: |
| 196 |
- guid |
| 197 |
- author |
| 198 |
register: status |
| 199 |
|
| 200 |
- name: Check for changed status |
| 201 |
assert: |
| 202 |
that: status is changed |
| 203 |
quiet: yes |
| 204 |
|
| 205 |
######## |
| 206 |
|
| 207 |
- name: Change something not in the config file (check) |
| 208 |
win_pssession_configuration: |
| 209 |
name: "{{ config_name }}" |
| 210 |
thread_options: reuse_thread |
| 211 |
use_shared_process: True |
| 212 |
register: status |
| 213 |
check_mode: yes |
| 214 |
|
| 215 |
- name: Check for changed status |
| 216 |
assert: |
| 217 |
that: status is changed |
| 218 |
quiet: yes |
| 219 |
|
| 220 |
- name: Change something not in the config file |
| 221 |
win_pssession_configuration: |
| 222 |
name: "{{ config_name }}" |
| 223 |
thread_options: reuse_thread |
| 224 |
use_shared_process: True |
| 225 |
register: status |
| 226 |
|
| 227 |
- name: Check for changed status |
| 228 |
assert: |
| 229 |
that: status is changed |
| 230 |
quiet: yes |
| 231 |
|
| 232 |
- name: Change something not in the config file (again) (check) |
| 233 |
win_pssession_configuration: |
| 234 |
name: "{{ config_name }}" |
| 235 |
thread_options: reuse_thread |
| 236 |
use_shared_process: True |
| 237 |
register: status |
| 238 |
check_mode: yes |
| 239 |
|
| 240 |
- name: Check for unchanged status |
| 241 |
assert: |
| 242 |
that: status is not changed |
| 243 |
quiet: yes |
| 244 |
|
| 245 |
- name: Change something not in the config file (again) |
| 246 |
win_pssession_configuration: |
| 247 |
name: "{{ config_name }}" |
| 248 |
thread_options: reuse_thread |
| 249 |
use_shared_process: True |
| 250 |
register: status |
| 251 |
|
| 252 |
- name: Check for unchanged status |
| 253 |
assert: |
| 254 |
that: status is not changed |
| 255 |
quiet: yes |
| 256 |
|
| 257 |
###### |
| 258 |
|
| 259 |
- name: Check custom type parameters for PowerShell <= 4 (check) |
| 260 |
win_pssession_configuration: |
| 261 |
name: "{{ config_name }}" |
| 262 |
guid: "{{ 'test' | to_uuid }}" |
| 263 |
powershell_version: '3.0' |
| 264 |
maximum_received_data_size_per_command_mb: 5.0E+11 |
| 265 |
maximum_received_object_size_mb: 6.6666666666666666666666666 |
| 266 |
register: status |
| 267 |
when: ansible_powershell_version <= 4 |
| 268 |
|
| 269 |
- name: Check custom type parameters for PowerShell >= 5 (check) |
| 270 |
win_pssession_configuration: |
| 271 |
name: "{{ config_name }}" |
| 272 |
guid: "{{ 'test' | to_uuid }}" |
| 273 |
powershell_version: '3.0' |
| 274 |
user_drive_maximum_size: 5000000000 |
| 275 |
maximum_received_data_size_per_command_mb: 5.0E+11 |
| 276 |
maximum_received_object_size_mb: 6.6666666666666666666666666 |
| 277 |
register: status |
| 278 |
when: ansible_powershell_version >= 5 |
| 279 |
|
| 280 |
###### |
| 281 |
|
| 282 |
- name: Reset back to a steady state |
| 283 |
win_pssession_configuration: |
| 284 |
name: "{{ config_name }}" |
| 285 |
register: status |
| 286 |
|
| 287 |
- name: Check for changed status |
| 288 |
assert: |
| 289 |
that: status is changed |
| 290 |
quiet: yes |
| 291 |
ignore_errors: yes |
| 292 |
|
| 293 |
- name: Reset back to a steady state (again) |
| 294 |
win_pssession_configuration: |
| 295 |
name: "{{ config_name }}" |
| 296 |
register: status |
| 297 |
|
| 298 |
- name: Check for unchanged status |
| 299 |
assert: |
| 300 |
that: status is not changed |
| 301 |
quiet: yes |
| 302 |
ignore_errors: yes |
| 303 |
|
| 304 |
####### |
| 305 |
|
| 306 |
- name: "RunAs Tests" |
| 307 |
vars: |
| 308 |
runas_user: "{{ ansible_user }}" |
| 309 |
runas_pass: "{{ ansible_password | default(ansible_test_connection_password) }}" |
| 310 |
block: |
| 311 |
- name: Change runas credential (check) |
| 312 |
win_pssession_configuration: |
| 313 |
name: "{{ config_name }}" |
| 314 |
run_as_credential_username: "{{ runas_user }}" |
| 315 |
run_as_credential_password: "{{ runas_pass }}" |
| 316 |
register: status |
| 317 |
check_mode: yes |
| 318 |
|
| 319 |
- name: Check for changed status |
| 320 |
assert: |
| 321 |
that: status is changed |
| 322 |
quiet: yes |
| 323 |
|
| 324 |
- name: Change runas credential |
| 325 |
win_pssession_configuration: |
| 326 |
name: "{{ config_name }}" |
| 327 |
run_as_credential_username: "{{ runas_user }}" |
| 328 |
run_as_credential_password: "{{ runas_pass }}" |
| 329 |
register: status |
| 330 |
|
| 331 |
- name: Check for changed status |
| 332 |
assert: |
| 333 |
that: status is changed |
| 334 |
quiet: yes |
| 335 |
|
| 336 |
- name: Try an invalid runas credential (failure expected) |
| 337 |
win_pssession_configuration: |
| 338 |
name: "{{ config_name }}" |
| 339 |
run_as_credential_username: Fake |
| 340 |
run_as_credential_password: Fake |
| 341 |
register: status |
| 342 |
ignore_errors: yes |
| 343 |
|
| 344 |
- name: Check for failed status |
| 345 |
assert: |
| 346 |
that: status is failed |
| 347 |
quiet: yes |
| 348 |
|
| 349 |
- name: Ensure the sessions configuration still exists with the working user |
| 350 |
ansible.windows.win_shell: | |
| 351 |
$sc = Get-PSSessionConfiguration -Name '{{ config_name }}' |
| 352 |
if ($sc.RunAsUser -ne '{{ runas_user }}') { |
| 353 |
throw |
| 354 |
} |
| 355 |
register: status |
| 356 |
|
| 357 |
####### |
| 358 |
|
| 359 |
- name: complex configuration for pwsh 5.1+ |
| 360 |
when: ansible_powershell_version > 4 |
| 361 |
block: |
| 362 |
- name: Create a complex configuration |
| 363 |
win_pssession_configuration: |
| 364 |
name: "{{ config_name }}" |
| 365 |
description: "{{ config_description }}" |
| 366 |
modules_to_import: Microsoft.PowerShell.Utility |
| 367 |
visible_aliases: [] |
| 368 |
visible_cmdlets: [] |
| 369 |
visible_external_commands: [] |
| 370 |
visible_functions: [] |
| 371 |
security_descriptor_sddl: "O:NSG:BAD:P(A;;GA;;;IU)(A;;GA;;;BA)(A;;GA;;;RM)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)" |
| 372 |
register: status |
| 373 |
|
| 374 |
- name: Check for changed status |
| 375 |
assert: |
| 376 |
that: status is changed |
| 377 |
quiet: yes |
| 378 |
|
| 379 |
- name: Create a complex configuration again (check) |
| 380 |
win_pssession_configuration: |
| 381 |
name: "{{ config_name }}" |
| 382 |
description: "{{ config_description }}" |
| 383 |
modules_to_import: Microsoft.PowerShell.Utility |
| 384 |
visible_aliases: [] |
| 385 |
visible_cmdlets: [] |
| 386 |
visible_external_commands: [] |
| 387 |
visible_functions: [] |
| 388 |
security_descriptor_sddl: "O:NSG:BAD:P(A;;GA;;;IU)(A;;GA;;;BA)(A;;GA;;;RM)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)" |
| 389 |
register: status |
| 390 |
check_mode: yes |
| 391 |
|
| 392 |
- name: Check for unchanged status |
| 393 |
assert: |
| 394 |
that: status is not changed |
| 395 |
quiet: yes |
| 396 |
|
| 397 |
- name: Create a complex configuration again |
| 398 |
win_pssession_configuration: |
| 399 |
name: "{{ config_name }}" |
| 400 |
description: "{{ config_description }}" |
| 401 |
modules_to_import: Microsoft.PowerShell.Utility |
| 402 |
visible_aliases: [] |
| 403 |
visible_cmdlets: [] |
| 404 |
visible_external_commands: [] |
| 405 |
visible_functions: [] |
| 406 |
security_descriptor_sddl: "O:NSG:BAD:P(A;;GA;;;IU)(A;;GA;;;BA)(A;;GA;;;RM)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)" |
| 407 |
register: status |
| 408 |
|
| 409 |
- name: Check for unchanged status |
| 410 |
assert: |
| 411 |
that: status is not changed |
| 412 |
quiet: yes |
| 413 |
|
| 414 |
####### |
| 415 |
|
| 416 |
- name: Test session configuration removal (check) |
| 417 |
win_pssession_configuration: |
| 418 |
name: "{{ config_name }}" |
| 419 |
state: absent |
| 420 |
register: status |
| 421 |
check_mode: yes |
| 422 |
|
| 423 |
- name: Check for changed status |
| 424 |
assert: |
| 425 |
that: status is changed |
| 426 |
quiet: yes |
| 427 |
|
| 428 |
- name: Test session configuration removal |
| 429 |
win_pssession_configuration: |
| 430 |
name: "{{ config_name }}" |
| 431 |
state: absent |
| 432 |
register: status |
| 433 |
|
| 434 |
- name: Check for changed status |
| 435 |
assert: |
| 436 |
that: status is changed |
| 437 |
quiet: yes |
| 438 |
|
| 439 |
- name: Test session configuration removal (again) |
| 440 |
win_pssession_configuration: |
| 441 |
name: "{{ config_name }}" |
| 442 |
state: absent |
| 443 |
register: status |
| 444 |
|
| 445 |
- name: Check for unchanged status |
| 446 |
assert: |
| 447 |
that: status is not changed |
| 448 |
quiet: yes |