1- name: test win_stat module on file 2 win_stat: 3 path: '{{win_stat_dir}}\nested\file.ps1' 4 register: stat_file 5 6- name: check actual for file 7 assert: 8 that: 9 - stat_file.stat.attributes == 'Archive' 10 - stat_file.stat.checksum == 'a9993e364706816aba3e25717850c26c9cd0d89d' 11 - stat_file.stat.creationtime == 1477984205 12 - stat_file.stat.exists == True 13 - stat_file.stat.extension == '.ps1' 14 - stat_file.stat.filename == 'file.ps1' 15 - stat_file.stat.hlnk_targets == [] 16 - stat_file.stat.isarchive == True 17 - stat_file.stat.isdir == False 18 - stat_file.stat.ishidden == False 19 - stat_file.stat.isjunction == False 20 - stat_file.stat.islnk == False 21 - stat_file.stat.isreadonly == False 22 - stat_file.stat.isreg == True 23 - stat_file.stat.isshared == False 24 - stat_file.stat.lastaccesstime == 1477984205 25 - stat_file.stat.lastwritetime == 1477984205 26 - stat_file.stat.nlink == 1 27 - stat_file.stat.owner == 'BUILTIN\Administrators' 28 - stat_file.stat.path == win_stat_dir + '\\nested\\file.ps1' 29 - stat_file.stat.size == 3 30 31- name: test win_stat module on file with sha256 32 win_stat: 33 path: '{{win_stat_dir}}\nested\file.ps1' 34 checksum_algorithm: sha256 35 register: stat_file_sha256 36 37- name: check actual for file with sha256 38 assert: 39 that: 40 - stat_file_sha256.stat.checksum == 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' 41 42- name: test win_stat module on file with sha384 43 win_stat: 44 path: '{{win_stat_dir}}\nested\file.ps1' 45 checksum_algorithm: sha384 46 register: stat_file_sha384 47 48- name: check actual for file with sha384 49 assert: 50 that: 51 - stat_file_sha384.stat.checksum == 'cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7' 52 53- name: test win_stat module on file with sha512 54 win_stat: 55 path: '{{win_stat_dir}}\nested\file.ps1' 56 checksum_algorithm: sha512 57 register: stat_file_sha512 58 59- name: check actual for file with sha512 60 assert: 61 that: 62 - stat_file_sha512.stat.checksum == 'ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f' 63 64- name: test win_stat on hidden file 65 win_stat: 66 path: '{{win_stat_dir}}\nested\hidden.ps1' 67 register: stat_file_hidden 68 69- name: check actual for hidden file 70 assert: 71 that: 72 - stat_file_hidden.stat.attributes == 'Hidden, Archive' 73 - stat_file_hidden.stat.checksum == 'a9993e364706816aba3e25717850c26c9cd0d89d' 74 - stat_file_hidden.stat.creationtime == 1477984205 75 - stat_file_hidden.stat.exists == True 76 - stat_file_hidden.stat.extension == '.ps1' 77 - stat_file_hidden.stat.filename == 'hidden.ps1' 78 - stat_file_hidden.stat.hlnk_targets == [] 79 - stat_file_hidden.stat.isarchive == True 80 - stat_file_hidden.stat.isdir == False 81 - stat_file_hidden.stat.ishidden == True 82 - stat_file_hidden.stat.isjunction == False 83 - stat_file_hidden.stat.islnk == False 84 - stat_file_hidden.stat.isreadonly == False 85 - stat_file_hidden.stat.isreg == True 86 - stat_file_hidden.stat.isshared == False 87 - stat_file_hidden.stat.lastaccesstime == 1477984205 88 - stat_file_hidden.stat.lastwritetime == 1477984205 89 - stat_file_hidden.stat.nlink == 1 90 - stat_file_hidden.stat.owner == 'BUILTIN\Administrators' 91 - stat_file_hidden.stat.path == win_stat_dir + '\\nested\\hidden.ps1' 92 - stat_file_hidden.stat.size == 3 93 94- name: test win_stat on readonly file 95 win_stat: 96 path: '{{win_stat_dir}}\nested\read-only.ps1' 97 register: stat_readonly 98 99- name: check actual for readonly file 100 assert: 101 that: 102 - stat_readonly.stat.attributes == 'ReadOnly, Archive' 103 - stat_readonly.stat.checksum == 'a9993e364706816aba3e25717850c26c9cd0d89d' 104 - stat_readonly.stat.creationtime == 1477984205 105 - stat_readonly.stat.exists == True 106 - stat_readonly.stat.extension == '.ps1' 107 - stat_readonly.stat.filename == 'read-only.ps1' 108 - stat_readonly.stat.hlnk_targets == [] 109 - stat_readonly.stat.isarchive == True 110 - stat_readonly.stat.isdir == False 111 - stat_readonly.stat.ishidden == False 112 - stat_readonly.stat.isjunction == False 113 - stat_readonly.stat.islnk == False 114 - stat_readonly.stat.isreadonly == True 115 - stat_readonly.stat.isreg == True 116 - stat_readonly.stat.isshared == False 117 - stat_readonly.stat.lastaccesstime == 1477984205 118 - stat_readonly.stat.lastwritetime == 1477984205 119 - stat_readonly.stat.nlink == 1 120 - stat_readonly.stat.owner == 'BUILTIN\Administrators' 121 - stat_readonly.stat.path == win_stat_dir + '\\nested\\read-only.ps1' 122 - stat_readonly.stat.size == 3 123 124- name: test win_stat on hard link file 125 win_stat: 126 path: '{{win_stat_dir}}\nested\hard-link.ps1' 127 follow: True # just verifies we don't do any weird follow logic for hard links 128 register: stat_hard_link 129 130- name: check actual for hard link file 131 assert: 132 that: 133 - stat_hard_link.stat.attributes == 'Archive' 134 - stat_hard_link.stat.checksum == 'a9993e364706816aba3e25717850c26c9cd0d89d' 135 - stat_hard_link.stat.creationtime == 1477984205 136 - stat_hard_link.stat.exists == True 137 - stat_hard_link.stat.extension == '.ps1' 138 - stat_hard_link.stat.filename == 'hard-link.ps1' 139 - stat_hard_link.stat.hlnk_targets == [ win_stat_dir + '\\nested\hard-target.txt' ] 140 - stat_hard_link.stat.isarchive == True 141 - stat_hard_link.stat.isdir == False 142 - stat_hard_link.stat.ishidden == False 143 - stat_hard_link.stat.isjunction == False 144 - stat_hard_link.stat.islnk == False 145 - stat_hard_link.stat.isreadonly == False 146 - stat_hard_link.stat.isshared == False 147 - stat_hard_link.stat.lastaccesstime == 1477984205 148 - stat_hard_link.stat.lastwritetime == 1477984205 149 - stat_hard_link.stat.nlink == 2 150 - stat_hard_link.stat.owner == 'BUILTIN\Administrators' 151 - stat_hard_link.stat.path == win_stat_dir + '\\nested\\hard-link.ps1' 152 - stat_hard_link.stat.size == 3 153 154- name: test win_stat on directory 155 win_stat: 156 path: '{{win_stat_dir}}\nested' 157 register: stat_directory 158 159- name: check actual for directory 160 assert: 161 that: 162 - stat_directory.stat.attributes == 'Directory' 163 - stat_directory.stat.checksum is not defined 164 - stat_directory.stat.creationtime == 1477984205 165 - stat_directory.stat.exists == True 166 - stat_directory.stat.extension is not defined 167 - stat_directory.stat.filename == 'nested' 168 - stat_directory.stat.hlnk_targets == [] 169 - stat_directory.stat.isarchive == False 170 - stat_directory.stat.isdir == True 171 - stat_directory.stat.ishidden == False 172 - stat_directory.stat.isjunction == False 173 - stat_directory.stat.islnk == False 174 - stat_directory.stat.isreadonly == False 175 - stat_directory.stat.isreg == False 176 - stat_directory.stat.isshared == False 177 - stat_directory.stat.lastaccesstime == 1477984205 178 - stat_directory.stat.lastwritetime == 1477984205 179 - stat_directory.stat.nlink == 1 180 - stat_directory.stat.owner == 'BUILTIN\Administrators' 181 - stat_directory.stat.path == win_stat_dir + '\\nested' 182 - stat_directory.stat.size == 24 183 184- name: test win_stat on empty directory 185 win_stat: 186 path: '{{win_stat_dir}}\folder' 187 register: stat_directory_empty 188 189- name: check actual for empty directory 190 assert: 191 that: 192 - stat_directory_empty.stat.attributes == 'Directory' 193 - stat_directory_empty.stat.checksum is not defined 194 - stat_directory_empty.stat.creationtime == 1477984205 195 - stat_directory_empty.stat.exists == True 196 - stat_directory_empty.stat.extension is not defined 197 - stat_directory_empty.stat.filename == 'folder' 198 - stat_directory_empty.stat.hlnk_targets == [] 199 - stat_directory_empty.stat.isarchive == False 200 - stat_directory_empty.stat.isdir == True 201 - stat_directory_empty.stat.ishidden == False 202 - stat_directory_empty.stat.isjunction == False 203 - stat_directory_empty.stat.islnk == False 204 - stat_directory_empty.stat.isreadonly == False 205 - stat_directory_empty.stat.isreg == False 206 - stat_directory_empty.stat.isshared == False 207 - stat_directory_empty.stat.lastaccesstime == 1477984205 208 - stat_directory_empty.stat.lastwritetime == 1477984205 209 - stat_directory_empty.stat.nlink == 1 210 - stat_directory_empty.stat.owner == 'BUILTIN\Administrators' 211 - stat_directory_empty.stat.path == win_stat_dir + '\\folder' 212 - stat_directory_empty.stat.size == 0 213 214- name: test win_stat on directory with space in name 215 win_stat: 216 path: '{{win_stat_dir}}\folder space' 217 register: stat_directory_space 218 219- name: check actual for directory with space in name 220 assert: 221 that: 222 - stat_directory_space.stat.attributes == 'Directory' 223 - stat_directory_space.stat.checksum is not defined 224 - stat_directory_space.stat.creationtime == 1477984205 225 - stat_directory_space.stat.exists == True 226 - stat_directory_space.stat.extension is not defined 227 - stat_directory_space.stat.filename == 'folder space' 228 - stat_directory_space.stat.hlnk_targets == [] 229 - stat_directory_space.stat.isarchive == False 230 - stat_directory_space.stat.isdir == True 231 - stat_directory_space.stat.ishidden == False 232 - stat_directory_space.stat.isjunction == False 233 - stat_directory_space.stat.islnk == False 234 - stat_directory_space.stat.isreadonly == False 235 - stat_directory_space.stat.isreg == False 236 - stat_directory_space.stat.isshared == False 237 - stat_directory_space.stat.lastaccesstime == 1477984205 238 - stat_directory_space.stat.lastwritetime == 1477984205 239 - stat_directory_space.stat.nlink == 1 240 - stat_directory_space.stat.owner == 'BUILTIN\Administrators' 241 - stat_directory_space.stat.path == win_stat_dir + '\\folder space' 242 - stat_directory_space.stat.size == 3 243 244- name: test win_stat on hidden directory 245 win_stat: 246 path: '{{win_stat_dir}}\hidden' 247 register: stat_hidden 248 249- name: check actual for hidden directory 250 assert: 251 that: 252 - stat_hidden.stat.attributes == 'Hidden, Directory' 253 - stat_hidden.stat.checksum is not defined 254 - stat_hidden.stat.creationtime == 1477984205 255 - stat_hidden.stat.exists == True 256 - stat_hidden.stat.extension is not defined 257 - stat_hidden.stat.filename == 'hidden' 258 - stat_hidden.stat.hlnk_targets == [] 259 - stat_hidden.stat.isarchive == False 260 - stat_hidden.stat.isdir == True 261 - stat_hidden.stat.ishidden == True 262 - stat_hidden.stat.isjunction == False 263 - stat_hidden.stat.islnk == False 264 - stat_hidden.stat.isreadonly == False 265 - stat_hidden.stat.isreg == False 266 - stat_hidden.stat.isshared == False 267 - stat_hidden.stat.lastaccesstime == 1477984205 268 - stat_hidden.stat.lastwritetime == 1477984205 269 - stat_hidden.stat.nlink == 1 270 - stat_hidden.stat.owner == 'BUILTIN\Administrators' 271 - stat_hidden.stat.path == win_stat_dir + '\\hidden' 272 - stat_hidden.stat.size == 0 273 274- name: test win_stat on shared directory 275 win_stat: 276 path: '{{win_stat_dir}}\shared' 277 register: stat_shared 278 279- name: check actual for shared directory 280 assert: 281 that: 282 - stat_shared.stat.attributes == 'Directory' 283 - stat_shared.stat.checksum is not defined 284 - stat_shared.stat.creationtime == 1477984205 285 - stat_shared.stat.exists == True 286 - stat_shared.stat.extension is not defined 287 - stat_shared.stat.filename == 'shared' 288 - stat_shared.stat.hlnk_targets == [] 289 - stat_shared.stat.isarchive == False 290 - stat_shared.stat.isdir == True 291 - stat_shared.stat.ishidden == False 292 - stat_shared.stat.isjunction == False 293 - stat_shared.stat.islnk == False 294 - stat_shared.stat.isreadonly == False 295 - stat_shared.stat.isreg == False 296 - stat_shared.stat.isshared == True 297 - stat_shared.stat.lastaccesstime == 1477984205 298 - stat_shared.stat.lastwritetime == 1477984205 299 - stat_shared.stat.nlink == 1 300 - stat_shared.stat.owner == 'BUILTIN\Administrators' 301 - stat_shared.stat.path == win_stat_dir + '\\shared' 302 - stat_shared.stat.sharename == 'folder-share' 303 - stat_shared.stat.size == 0 304 305- name: test win_stat on directory symlink 306 win_stat: 307 path: '{{win_stat_dir}}\link' 308 register: stat_symlink 309 310- name: assert directory symlink actual 311 assert: 312 that: 313 - stat_symlink.stat.attributes == 'Directory, ReparsePoint' 314 - stat_symlink.stat.creationtime is defined 315 - stat_symlink.stat.exists == True 316 - stat_symlink.stat.filename == 'link' 317 - stat_symlink.stat.hlnk_targets == [] 318 - stat_symlink.stat.isarchive == False 319 - stat_symlink.stat.isdir == True 320 - stat_symlink.stat.ishidden == False 321 - stat_symlink.stat.islnk == True 322 - stat_symlink.stat.isjunction == False 323 - stat_symlink.stat.isreadonly == False 324 - stat_symlink.stat.isreg == False 325 - stat_symlink.stat.isshared == False 326 - stat_symlink.stat.lastaccesstime is defined 327 - stat_symlink.stat.lastwritetime is defined 328 - stat_symlink.stat.lnk_source == win_stat_dir + '\\link-dest' 329 - stat_symlink.stat.lnk_target == win_stat_dir + '\\link-dest' 330 - stat_symlink.stat.nlink == 1 331 - stat_symlink.stat.owner == 'BUILTIN\\Administrators' 332 - stat_symlink.stat.path == win_stat_dir + '\\link' 333 - stat_symlink.stat.checksum is not defined 334 335- name: test win_stat on file symlink 336 win_stat: 337 path: '{{win_stat_dir}}\file-link.txt' 338 register: stat_file_symlink 339 340- name: assert file symlink actual 341 assert: 342 that: 343 - stat_file_symlink.stat.attributes == 'Archive, ReparsePoint' 344 - stat_file_symlink.stat.checksum == 'a9993e364706816aba3e25717850c26c9cd0d89d' 345 - stat_file_symlink.stat.creationtime is defined 346 - stat_file_symlink.stat.exists == True 347 - stat_file_symlink.stat.extension == '.txt' 348 - stat_file_symlink.stat.filename == 'file-link.txt' 349 - stat_file_symlink.stat.hlnk_targets == [] 350 - stat_file_symlink.stat.isarchive == True 351 - stat_file_symlink.stat.isdir == False 352 - stat_file_symlink.stat.ishidden == False 353 - stat_file_symlink.stat.isjunction == False 354 - stat_file_symlink.stat.islnk == True 355 - stat_file_symlink.stat.isreadonly == False 356 - stat_file_symlink.stat.isreg == False 357 - stat_file_symlink.stat.isshared == False 358 - stat_file_symlink.stat.lastaccesstime is defined 359 - stat_file_symlink.stat.lastwritetime is defined 360 - stat_file_symlink.stat.lnk_source == win_stat_dir + '\\nested\\file.ps1' 361 - stat_file_symlink.stat.lnk_target == win_stat_dir + '\\nested\\file.ps1' 362 - stat_file_symlink.stat.nlink == 1 363 - stat_file_symlink.stat.owner == 'BUILTIN\\Administrators' 364 - stat_file_symlink.stat.path == win_stat_dir + '\\file-link.txt' 365 366- name: test win_stat of file symlink with follow 367 win_stat: 368 path: '{{win_stat_dir}}\file-link.txt' 369 follow: True 370 register: stat_file_symlink_follow 371 372- name: assert file system with follow actual 373 assert: 374 that: 375 - stat_file_symlink_follow.stat.attributes == 'Archive' 376 - stat_file_symlink_follow.stat.checksum == 'a9993e364706816aba3e25717850c26c9cd0d89d' 377 - stat_file_symlink_follow.stat.creationtime is defined 378 - stat_file_symlink_follow.stat.exists == True 379 - stat_file_symlink_follow.stat.extension == '.ps1' 380 - stat_file_symlink_follow.stat.filename == 'file.ps1' 381 - stat_file_symlink_follow.stat.hlnk_targets == [] 382 - stat_file_symlink_follow.stat.isarchive == True 383 - stat_file_symlink_follow.stat.isdir == False 384 - stat_file_symlink_follow.stat.ishidden == False 385 - stat_file_symlink_follow.stat.isjunction == False 386 - stat_file_symlink_follow.stat.islnk == False 387 - stat_file_symlink_follow.stat.isreadonly == False 388 - stat_file_symlink_follow.stat.isreg == True 389 - stat_file_symlink_follow.stat.isshared == False 390 - stat_file_symlink_follow.stat.lastaccesstime is defined 391 - stat_file_symlink_follow.stat.lastwritetime is defined 392 - stat_file_symlink_follow.stat.nlink == 1 393 - stat_file_symlink_follow.stat.owner == 'BUILTIN\\Administrators' 394 - stat_file_symlink_follow.stat.path == win_stat_dir + '\\nested\\file.ps1' 395 396- name: test win_stat on relative symlink 397 win_stat: 398 path: '{{win_stat_dir}}\nested\nested\link-rel' 399 register: stat_rel_symlink 400 401- name: assert directory relative symlink actual 402 assert: 403 that: 404 - stat_rel_symlink.stat.attributes == 'Directory, ReparsePoint' 405 - stat_rel_symlink.stat.creationtime is defined 406 - stat_rel_symlink.stat.exists == True 407 - stat_rel_symlink.stat.filename == 'link-rel' 408 - stat_rel_symlink.stat.hlnk_targets == [] 409 - stat_rel_symlink.stat.isarchive == False 410 - stat_rel_symlink.stat.isdir == True 411 - stat_rel_symlink.stat.ishidden == False 412 - stat_rel_symlink.stat.isjunction == False 413 - stat_rel_symlink.stat.islnk == True 414 - stat_rel_symlink.stat.isreadonly == False 415 - stat_rel_symlink.stat.isreg == False 416 - stat_rel_symlink.stat.isshared == False 417 - stat_rel_symlink.stat.lastaccesstime is defined 418 - stat_rel_symlink.stat.lastwritetime is defined 419 - stat_rel_symlink.stat.lnk_source == win_stat_dir + '\\link-dest' 420 - stat_rel_symlink.stat.lnk_target == '..\\..\\link-dest' 421 - stat_rel_symlink.stat.nlink == 1 422 - stat_rel_symlink.stat.owner == 'BUILTIN\\Administrators' 423 - stat_rel_symlink.stat.path == win_stat_dir + '\\nested\\nested\\link-rel' 424 - stat_rel_symlink.stat.checksum is not defined 425 426- name: test win_stat on relative multiple symlink with follow 427 win_stat: 428 path: '{{win_stat_dir}}\outer-link' 429 follow: True 430 register: stat_symlink_follow 431 432- name: assert directory relative symlink actual 433 assert: 434 that: 435 - stat_symlink_follow.stat.attributes == 'Directory' 436 - stat_symlink_follow.stat.creationtime is defined 437 - stat_symlink_follow.stat.exists == True 438 - stat_symlink_follow.stat.filename == 'link-dest' 439 - stat_symlink_follow.stat.hlnk_targets == [] 440 - stat_symlink_follow.stat.isarchive == False 441 - stat_symlink_follow.stat.isdir == True 442 - stat_symlink_follow.stat.ishidden == False 443 - stat_symlink_follow.stat.isjunction == False 444 - stat_symlink_follow.stat.islnk == False 445 - stat_symlink_follow.stat.isreadonly == False 446 - stat_symlink_follow.stat.isreg == False 447 - stat_symlink_follow.stat.isshared == False 448 - stat_symlink_follow.stat.lastaccesstime is defined 449 - stat_symlink_follow.stat.lastwritetime is defined 450 - stat_symlink_follow.stat.nlink == 1 451 - stat_symlink_follow.stat.owner == 'BUILTIN\\Administrators' 452 - stat_symlink_follow.stat.path == win_stat_dir + '\\link-dest' 453 - stat_symlink_follow.stat.checksum is not defined 454 455- name: test win_stat on junction 456 win_stat: 457 path: '{{win_stat_dir}}\junction-link' 458 register: stat_junction_point 459 460- name: assert junction actual 461 assert: 462 that: 463 - stat_junction_point.stat.attributes == 'Directory, ReparsePoint' 464 - stat_junction_point.stat.creationtime is defined 465 - stat_junction_point.stat.exists == True 466 - stat_junction_point.stat.filename == 'junction-link' 467 - stat_junction_point.stat.hlnk_targets == [] 468 - stat_junction_point.stat.isarchive == False 469 - stat_junction_point.stat.isdir == True 470 - stat_junction_point.stat.ishidden == False 471 - stat_junction_point.stat.isjunction == True 472 - stat_junction_point.stat.islnk == False 473 - stat_junction_point.stat.isreadonly == False 474 - stat_junction_point.stat.isreg == False 475 - stat_junction_point.stat.isshared == False 476 - stat_junction_point.stat.lastaccesstime is defined 477 - stat_junction_point.stat.lastwritetime is defined 478 - stat_junction_point.stat.lnk_source == win_stat_dir + '\\junction-dest' 479 - stat_junction_point.stat.lnk_target == win_stat_dir + '\\junction-dest' 480 - stat_junction_point.stat.nlink == 1 481 - stat_junction_point.stat.owner == 'BUILTIN\\Administrators' 482 - stat_junction_point.stat.path == win_stat_dir + '\\junction-link' 483 - stat_junction_point.stat.size == 0 484 485- name: test win_stat on junction with follow 486 win_stat: 487 path: '{{win_stat_dir}}\junction-link' 488 follow: True 489 register: stat_junction_point_follow 490 491- name: assert junction with follow actual 492 assert: 493 that: 494 - stat_junction_point_follow.stat.attributes == 'Directory' 495 - stat_junction_point_follow.stat.creationtime is defined 496 - stat_junction_point_follow.stat.exists == True 497 - stat_junction_point_follow.stat.filename == 'junction-dest' 498 - stat_junction_point_follow.stat.hlnk_targets == [] 499 - stat_junction_point_follow.stat.isarchive == False 500 - stat_junction_point_follow.stat.isdir == True 501 - stat_junction_point_follow.stat.ishidden == False 502 - stat_junction_point_follow.stat.isjunction == False 503 - stat_junction_point_follow.stat.islnk == False 504 - stat_junction_point_follow.stat.isreadonly == False 505 - stat_junction_point_follow.stat.isreg == False 506 - stat_junction_point_follow.stat.isshared == False 507 - stat_junction_point_follow.stat.lastaccesstime is defined 508 - stat_junction_point_follow.stat.lastwritetime is defined 509 - stat_junction_point_follow.stat.nlink == 1 510 - stat_junction_point_follow.stat.owner == 'BUILTIN\\Administrators' 511 - stat_junction_point_follow.stat.path == win_stat_dir + '\\junction-dest' 512 - stat_junction_point_follow.stat.size == 0 513 514- name: test win_stat module non-existent path 515 win_stat: 516 path: '{{win_stat_dir}}\this_file_should_not_exist' 517 register: win_stat_missing 518 519- name: check win_stat missing result 520 assert: 521 that: 522 - not win_stat_missing.stat.exists 523 - win_stat_missing is not failed 524 - win_stat_missing is not changed 525 526- name: test win_stat module without path argument 527 win_stat: 528 register: win_stat_no_args 529 failed_when: "win_stat_no_args.msg != 'missing required arguments: path'" 530 531# https://github.com/ansible/ansible/issues/30258 532- name: get path of pagefile 533 win_shell: | 534 $pagefile = $null 535 $cs = Get-CimInstance -ClassName Win32_ComputerSystem 536 if ($cs.AutomaticManagedPagefile) { 537 $pagefile = "$($env:SystemRoot.Substring(0, 1)):\pagefile.sys" 538 } else { 539 $pf = Get-CimInstance -ClassName Win32_PageFileSetting 540 if ($pf -ne $null) { 541 $pagefile = $pf[0].Name 542 } 543 } 544 $pagefile 545 register: pagefile_path 546 547- name: get stat of pagefile 548 win_stat: 549 path: '{{pagefile_path.stdout_lines[0]}}' 550 get_checksum: no 551 register: pagefile_stat 552 when: pagefile_path.stdout_lines|count != 0 553 554- name: assert get stat of pagefile 555 assert: 556 that: 557 - pagefile_stat.stat.exists == True 558 when: pagefile_path.stdout_lines|count != 0 559 560# Tests with normal user 561- set_fact: 562 gen_pw: password123! + {{ lookup('password', '/dev/null chars=ascii_letters,digits length=8') }} 563 564- name: create test user 565 win_user: 566 name: '{{win_stat_user}}' 567 password: '{{gen_pw}}' 568 update_password: always 569 groups: Users 570 571- name: get become user profile dir so we can clean it up later 572 vars: &become_vars 573 ansible_become_user: '{{win_stat_user}}' 574 ansible_become_password: '{{gen_pw}}' 575 ansible_become_method: runas 576 ansible_become: yes 577 win_shell: $env:USERPROFILE 578 register: profile_dir_out 579 580- name: ensure profile dir contains test username (eg, if become fails silently, prevent deletion of real user profile) 581 assert: 582 that: 583 - win_stat_user in profile_dir_out.stdout_lines[0] 584 585- name: test stat with non admin user on a normal file 586 vars: *become_vars 587 win_stat: 588 path: '{{win_stat_dir}}\nested\file.ps1' 589 register: user_file 590 591- name: asert test stat with non admin user on a normal file 592 assert: 593 that: 594 - user_file.stat.attributes == 'Archive' 595 - user_file.stat.checksum == 'a9993e364706816aba3e25717850c26c9cd0d89d' 596 - user_file.stat.creationtime == 1477984205 597 - user_file.stat.exists == True 598 - user_file.stat.extension == '.ps1' 599 - user_file.stat.filename == 'file.ps1' 600 - user_file.stat.hlnk_targets == [] 601 - user_file.stat.isarchive == True 602 - user_file.stat.isdir == False 603 - user_file.stat.ishidden == False 604 - user_file.stat.isjunction == False 605 - user_file.stat.islnk == False 606 - user_file.stat.isreadonly == False 607 - user_file.stat.isreg == True 608 - user_file.stat.isshared == False 609 - user_file.stat.lastaccesstime == 1477984205 610 - user_file.stat.lastwritetime == 1477984205 611 - user_file.stat.nlink == 1 612 - user_file.stat.owner == 'BUILTIN\\Administrators' 613 - user_file.stat.path == win_stat_dir + '\\nested\\file.ps1' 614 - user_file.stat.size == 3 615 616- name: test stat on a symbolic link as normal user 617 vars: *become_vars 618 win_stat: 619 path: '{{win_stat_dir}}\link' 620 register: user_symlink 621 622- name: assert test stat on a symbolic link as normal user 623 assert: 624 that: 625 - user_symlink.stat.attributes == 'Directory, ReparsePoint' 626 - user_symlink.stat.creationtime is defined 627 - user_symlink.stat.exists == True 628 - user_symlink.stat.filename == 'link' 629 - user_symlink.stat.hlnk_targets == [] 630 - user_symlink.stat.isarchive == False 631 - user_symlink.stat.isdir == True 632 - user_symlink.stat.ishidden == False 633 - user_symlink.stat.islnk == True 634 - user_symlink.stat.isjunction == False 635 - user_symlink.stat.isreadonly == False 636 - user_symlink.stat.isreg == False 637 - user_symlink.stat.isshared == False 638 - user_symlink.stat.lastaccesstime is defined 639 - user_symlink.stat.lastwritetime is defined 640 - user_symlink.stat.lnk_source == win_stat_dir + '\\link-dest' 641 - user_symlink.stat.lnk_target == win_stat_dir + '\\link-dest' 642 - user_symlink.stat.nlink == 1 643 - user_symlink.stat.owner == 'BUILTIN\\Administrators' 644 - user_symlink.stat.path == win_stat_dir + '\\link' 645 - user_symlink.stat.checksum is not defined 646