| 1 |
# Test code for the file module. |
| 2 |
# (c) 2017, Dag Wieers <[email protected]> |
| 3 |
|
| 4 |
# This file is part of Ansible |
| 5 |
# |
| 6 |
# Ansible is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# Ansible is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
- name: get current user profile location |
| 20 |
raw: $env:USERPROFILE |
| 21 |
check_mode: no |
| 22 |
register: profile_result |
| 23 |
|
| 24 |
- set_fact: |
| 25 |
profile_dir: '{{ profile_result.stdout_lines[0] }}' |
| 26 |
|
| 27 |
- name: Add Ansible website link on the desktop |
| 28 |
win_shortcut: |
| 29 |
src: https://ansible.com/ |
| 30 |
dest: '%UserProfile%\Desktop\Ansible website.url' |
| 31 |
state: present |
| 32 |
register: ansible_website_link_add |
| 33 |
|
| 34 |
- name: Check there was a change |
| 35 |
assert: |
| 36 |
that: |
| 37 |
- ansible_website_link_add.changed == true |
| 38 |
- ansible_website_link_add.dest == profile_dir + '\Desktop\Ansible website.url' |
| 39 |
- ansible_website_link_add.src == 'https://ansible.com/' |
| 40 |
|
| 41 |
- name: Add Ansible website link on the desktop again |
| 42 |
win_shortcut: |
| 43 |
src: https://ansible.com/ |
| 44 |
dest: '%UserProfile%\Desktop\Ansible website.url' |
| 45 |
state: present |
| 46 |
register: ansible_website_link_add_again |
| 47 |
|
| 48 |
- name: Check there was no change (normal mode) |
| 49 |
assert: |
| 50 |
that: |
| 51 |
- ansible_website_link_add_again.changed == false |
| 52 |
- ansible_website_link_add_again.dest == profile_dir + '\Desktop\Ansible website.url' |
| 53 |
- ansible_website_link_add_again.src == 'https://ansible.com/' |
| 54 |
when: not in_check_mode |
| 55 |
|
| 56 |
- name: Check there was a change (check-mode) |
| 57 |
assert: |
| 58 |
that: |
| 59 |
- ansible_website_link_add_again.changed == true |
| 60 |
- ansible_website_link_add_again.dest == profile_dir + '\Desktop\Ansible website.url' |
| 61 |
- ansible_website_link_add_again.src == 'https://ansible.com/' |
| 62 |
when: in_check_mode |
| 63 |
|
| 64 |
- name: Remove link |
| 65 |
win_shortcut: |
| 66 |
dest: '%UserProfile%\Desktop\Ansible website.url' |
| 67 |
state: absent |
| 68 |
register: ansible_website_link_remove |
| 69 |
|
| 70 |
- name: Check there was a change (normal mode) |
| 71 |
assert: |
| 72 |
that: |
| 73 |
- ansible_website_link_remove.changed == true |
| 74 |
- ansible_website_link_remove.dest == profile_dir + '\Desktop\Ansible website.url' |
| 75 |
when: not in_check_mode |
| 76 |
|
| 77 |
- name: Check there was no change (check-mode) |
| 78 |
assert: |
| 79 |
that: |
| 80 |
- ansible_website_link_remove.changed == false |
| 81 |
- ansible_website_link_remove.dest == profile_dir + '\Desktop\Ansible website.url' |
| 82 |
when: in_check_mode |
| 83 |
|
| 84 |
- name: Remove link again |
| 85 |
win_shortcut: |
| 86 |
dest: '%UserProfile%\Desktop\Ansible website.url' |
| 87 |
state: absent |
| 88 |
register: ansible_website_link_remove_again |
| 89 |
|
| 90 |
- name: Check there was no change |
| 91 |
assert: |
| 92 |
that: |
| 93 |
- ansible_website_link_remove_again.changed == false |
| 94 |
- ansible_website_link_remove_again.dest == profile_dir + '\Desktop\Ansible website.url' |
| 95 |
|
| 96 |
- name: Add a regedit shortcut on the desktop |
| 97 |
win_shortcut: |
| 98 |
description: "Registry Editor" |
| 99 |
src: regedit.exe |
| 100 |
dest: '%Public%\Desktop\Registry Editor.lnk' |
| 101 |
state: present |
| 102 |
register: regedit_shortcut_add |
| 103 |
|
| 104 |
- name: Check there was a change |
| 105 |
assert: |
| 106 |
that: |
| 107 |
- regedit_shortcut_add.changed == true |
| 108 |
- regedit_shortcut_add.description == 'Registry Editor' |
| 109 |
- regedit_shortcut_add.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 110 |
- regedit_shortcut_add.src == 'C:\\Windows\\regedit.exe' |
| 111 |
|
| 112 |
- name: Add a regedit shortcut on the desktop again |
| 113 |
win_shortcut: |
| 114 |
description: "Registry Editor" |
| 115 |
src: regedit.exe |
| 116 |
dest: '%Public%\Desktop\Registry Editor.lnk' |
| 117 |
state: present |
| 118 |
register: regedit_shortcut_add_again |
| 119 |
|
| 120 |
- name: Check there was no change (normal mode) |
| 121 |
assert: |
| 122 |
that: |
| 123 |
- regedit_shortcut_add_again.changed == false |
| 124 |
- regedit_shortcut_add_again.description == 'Registry Editor' |
| 125 |
- regedit_shortcut_add_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 126 |
- regedit_shortcut_add_again.src == 'C:\\Windows\\regedit.exe' |
| 127 |
when: not in_check_mode |
| 128 |
|
| 129 |
- name: Check there was a change (check-mode) |
| 130 |
assert: |
| 131 |
that: |
| 132 |
- regedit_shortcut_add_again.changed == true |
| 133 |
- regedit_shortcut_add_again.description == 'Registry Editor' |
| 134 |
- regedit_shortcut_add_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 135 |
- regedit_shortcut_add_again.src == 'C:\\Windows\\regedit.exe' |
| 136 |
when: in_check_mode |
| 137 |
|
| 138 |
- name: Update a regedit shortcut on the desktop |
| 139 |
win_shortcut: |
| 140 |
description: "Registry Editor" |
| 141 |
src: C:\BogusPath\regedit.exe |
| 142 |
dest: '%Public%\Desktop\Registry Editor.lnk' |
| 143 |
state: present |
| 144 |
register: regedit_shortcut_update |
| 145 |
|
| 146 |
- name: Check there was a change |
| 147 |
assert: |
| 148 |
that: |
| 149 |
- regedit_shortcut_update.changed == true |
| 150 |
- regedit_shortcut_update.description == 'Registry Editor' |
| 151 |
- regedit_shortcut_update.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 152 |
- regedit_shortcut_update.src == 'C:\\BogusPath\\regedit.exe' |
| 153 |
|
| 154 |
- name: Update a regedit shortcut on the desktop again |
| 155 |
win_shortcut: |
| 156 |
description: "Registry Editor" |
| 157 |
src: C:\BogusPath\regedit.exe |
| 158 |
dest: '%Public%\Desktop\Registry Editor.lnk' |
| 159 |
state: present |
| 160 |
register: regedit_shortcut_update_again |
| 161 |
|
| 162 |
- name: Check there was no change (normal mode) |
| 163 |
assert: |
| 164 |
that: |
| 165 |
- regedit_shortcut_update_again.changed == false |
| 166 |
- regedit_shortcut_update_again.description == 'Registry Editor' |
| 167 |
- regedit_shortcut_update_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 168 |
- regedit_shortcut_update_again.src == 'C:\\BogusPath\\regedit.exe' |
| 169 |
when: not in_check_mode |
| 170 |
|
| 171 |
- name: Check there was a change (check-mode) |
| 172 |
assert: |
| 173 |
that: |
| 174 |
- regedit_shortcut_update_again.changed == true |
| 175 |
- regedit_shortcut_update_again.description == 'Registry Editor' |
| 176 |
- regedit_shortcut_update_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 177 |
- regedit_shortcut_update_again.src == 'C:\\BogusPath\\regedit.exe' |
| 178 |
when: in_check_mode |
| 179 |
|
| 180 |
- name: Add an (explicit) icon |
| 181 |
win_shortcut: |
| 182 |
description: "Registry Editor" |
| 183 |
src: C:\Windows\regedit.exe |
| 184 |
dest: '%Public%\Desktop\Registry Editor.lnk' |
| 185 |
icon: 'C:\Windows\regedit.exe,0' |
| 186 |
state: present |
| 187 |
register: regedit_shortcut_add_icon |
| 188 |
|
| 189 |
- name: Check there was a change |
| 190 |
assert: |
| 191 |
that: |
| 192 |
- regedit_shortcut_add_icon.changed == true |
| 193 |
- regedit_shortcut_add_icon.description == 'Registry Editor' |
| 194 |
- regedit_shortcut_add_icon.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 195 |
- regedit_shortcut_add_icon.icon == 'C:\\Windows\\regedit.exe,0' |
| 196 |
- regedit_shortcut_add_icon.src == 'C:\\Windows\\regedit.exe' |
| 197 |
|
| 198 |
- name: Add an (explicit) icon again |
| 199 |
win_shortcut: |
| 200 |
description: "Registry Editor" |
| 201 |
src: C:\Windows\regedit.exe |
| 202 |
dest: '%Public%\Desktop\Registry Editor.lnk' |
| 203 |
icon: 'C:\Windows\regedit.exe,0' |
| 204 |
state: present |
| 205 |
register: regedit_shortcut_add_icon_again |
| 206 |
|
| 207 |
- name: Check there was no change (normal mode) |
| 208 |
assert: |
| 209 |
that: |
| 210 |
- regedit_shortcut_add_icon_again.changed == false |
| 211 |
- regedit_shortcut_add_icon_again.description == 'Registry Editor' |
| 212 |
- regedit_shortcut_add_icon_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 213 |
- regedit_shortcut_add_icon_again.icon == 'C:\\Windows\\regedit.exe,0' |
| 214 |
- regedit_shortcut_add_icon_again.src == 'C:\\Windows\\regedit.exe' |
| 215 |
when: not in_check_mode |
| 216 |
|
| 217 |
- name: Check there was a change (check-mode) |
| 218 |
assert: |
| 219 |
that: |
| 220 |
- regedit_shortcut_add_icon_again.changed == true |
| 221 |
- regedit_shortcut_add_icon_again.description == 'Registry Editor' |
| 222 |
- regedit_shortcut_add_icon_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 223 |
- regedit_shortcut_add_icon_again.icon == 'C:\\Windows\\regedit.exe,0' |
| 224 |
- regedit_shortcut_add_icon_again.src == 'C:\\Windows\\regedit.exe' |
| 225 |
when: in_check_mode |
| 226 |
|
| 227 |
- name: Remove shortcut |
| 228 |
win_shortcut: |
| 229 |
dest: '%Public%\Desktop\Registry Editor.lnk' |
| 230 |
state: absent |
| 231 |
register: regedit_shortcut_remove |
| 232 |
|
| 233 |
- name: Check there was a change (normal mode) |
| 234 |
assert: |
| 235 |
that: |
| 236 |
- regedit_shortcut_remove.changed == true |
| 237 |
- regedit_shortcut_remove.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 238 |
when: not in_check_mode |
| 239 |
|
| 240 |
- name: Check there was no change (check-mode) |
| 241 |
assert: |
| 242 |
that: |
| 243 |
- regedit_shortcut_remove.changed == false |
| 244 |
- regedit_shortcut_remove.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 245 |
when: in_check_mode |
| 246 |
|
| 247 |
- name: Remove shortcut again |
| 248 |
win_shortcut: |
| 249 |
dest: '%Public%\Desktop\Registry Editor.lnk' |
| 250 |
state: absent |
| 251 |
register: regedit_shortcut_remove_again |
| 252 |
|
| 253 |
- name: Check there was no change |
| 254 |
assert: |
| 255 |
that: |
| 256 |
- regedit_shortcut_remove_again.changed == false |
| 257 |
- regedit_shortcut_remove_again.dest == 'C:\\Users\\Public\\Desktop\\Registry Editor.lnk' |
| 258 |
|
| 259 |
- name: Create shortcut to shell path |
| 260 |
win_shortcut: |
| 261 |
dest: '%Public%\bin.lnk' |
| 262 |
src: shell:RecycleBinFolder |
| 263 |
state: present |
| 264 |
register: shell_add |
| 265 |
|
| 266 |
- name: Check there was a change |
| 267 |
assert: |
| 268 |
that: |
| 269 |
- shell_add is changed |
| 270 |
- shell_add.dest == 'C:\\Users\\Public\\bin.lnk' |
| 271 |
- shell_add.src == 'shell:RecycleBinFolder' |
| 272 |
|
| 273 |
- name: Create shortcut to shell path again |
| 274 |
win_shortcut: |
| 275 |
dest: '%Public%\bin.lnk' |
| 276 |
src: shell:RecycleBinFolder |
| 277 |
state: present |
| 278 |
register: shell_add_again |
| 279 |
|
| 280 |
- name: Check there was no change (normal mode) |
| 281 |
assert: |
| 282 |
that: |
| 283 |
- not shell_add_again is changed |
| 284 |
- shell_add_again.src == 'shell:RecycleBinFolder' |
| 285 |
when: not in_check_mode |
| 286 |
|
| 287 |
- name: Check there was a change (check-mode) |
| 288 |
assert: |
| 289 |
that: |
| 290 |
- shell_add_again is changed |
| 291 |
when: in_check_mode |
| 292 |
|
| 293 |
- name: Change shortcut to another shell path |
| 294 |
win_shortcut: |
| 295 |
dest: '%Public%\bin.lnk' |
| 296 |
src: shell:Start Menu |
| 297 |
state: present |
| 298 |
register: shell_change |
| 299 |
|
| 300 |
- name: Check there was a change |
| 301 |
assert: |
| 302 |
that: |
| 303 |
- shell_change is changed |
| 304 |
- shell_change.src == 'shell:Start Menu' |
| 305 |
|
| 306 |
- name: Create shortcut to an executable without run as admin |
| 307 |
win_shortcut: |
| 308 |
dest: '%Public%\Desktop\cmd.lnk' |
| 309 |
src: '%SystemRoot%\System32\cmd.exe' |
| 310 |
state: present |
| 311 |
register: shell_exe_limited |
| 312 |
|
| 313 |
- name: Get run as admin flag state |
| 314 |
ansible.windows.win_shell: | |
| 315 |
$shortcut = "$env:Public\Desktop\cmd.lnk" |
| 316 |
$flags = [System.BitConverter]::ToUInt32([System.IO.FIle]::ReadAllBytes($shortcut), 20) |
| 317 |
($flags -band 0x00002000) -eq 0x00002000 |
| 318 |
register: shell_exe_limited_actual |
| 319 |
|
| 320 |
- name: Check that run as admin flag wasn't set (normal mode) |
| 321 |
assert: |
| 322 |
that: |
| 323 |
- shell_exe_limited is changed |
| 324 |
- not shell_exe_limited_actual.stdout_lines[0]|bool |
| 325 |
when: not in_check_mode |
| 326 |
|
| 327 |
- name: Check that exe shortcut results in a change (check-mode) |
| 328 |
assert: |
| 329 |
that: |
| 330 |
- shell_exe_limited is changed |
| 331 |
when: in_check_mode |
| 332 |
|
| 333 |
- name: Set shortcut to run as admin |
| 334 |
win_shortcut: |
| 335 |
dest: '%Public%\Desktop\cmd.lnk' |
| 336 |
src: '%SystemRoot%\System32\cmd.exe' |
| 337 |
run_as_admin: True |
| 338 |
state: present |
| 339 |
register: shell_exe_admin |
| 340 |
|
| 341 |
- name: Get run as admin flag state |
| 342 |
ansible.windows.win_shell: | |
| 343 |
$shortcut = "$env:Public\Desktop\cmd.lnk" |
| 344 |
$flags = [System.BitConverter]::ToUInt32([System.IO.FIle]::ReadAllBytes($shortcut), 20) |
| 345 |
($flags -band 0x00002000) -eq 0x00002000 |
| 346 |
register: shell_exe_admin_actual |
| 347 |
|
| 348 |
- name: Check that run as admin flag was set (normal mode) |
| 349 |
assert: |
| 350 |
that: |
| 351 |
- shell_exe_admin is changed |
| 352 |
- shell_exe_admin_actual.stdout_lines[0]|bool |
| 353 |
when: not in_check_mode |
| 354 |
|
| 355 |
- name: Set shortcut to run as admin again |
| 356 |
win_shortcut: |
| 357 |
dest: '%Public%\Desktop\cmd.lnk' |
| 358 |
src: '%SystemRoot%\System32\cmd.exe' |
| 359 |
run_as_admin: True |
| 360 |
state: present |
| 361 |
register: shell_exe_admin_again |
| 362 |
|
| 363 |
- name: Check that set run as admin wasn't changed (normal mode) |
| 364 |
assert: |
| 365 |
that: |
| 366 |
- not shell_exe_admin_again is changed |
| 367 |
when: not in_check_mode |