| 1 |
- name: join domain invalid OU |
| 2 |
membership: |
| 3 |
dns_domain_name: '{{ domain_realm }}' |
| 4 |
domain_admin_user: '{{ domain_user_upn }}' |
| 5 |
domain_admin_password: '{{ domain_password }}' |
| 6 |
domain_ou_path: CN=Invalid,{{ domain_dn_base }} |
| 7 |
state: domain |
| 8 |
reboot: true |
| 9 |
ignore_errors: true |
| 10 |
register: join_domain_invalid_ou |
| 11 |
|
| 12 |
- name: assert join domain invalid OU |
| 13 |
assert: |
| 14 |
that: |
| 15 |
- join_domain_invalid_ou is failed |
| 16 |
- join_domain_invalid_ou.msg.endswith('Check domain_ou_path is pointing to a valid OU in the target domain.') |
| 17 |
|
| 18 |
- name: join domain - check mode |
| 19 |
membership: |
| 20 |
dns_domain_name: '{{ domain_realm }}' |
| 21 |
domain_admin_user: '{{ domain_user_upn }}' |
| 22 |
domain_admin_password: '{{ domain_password }}' |
| 23 |
state: domain |
| 24 |
reboot: true |
| 25 |
check_mode: true |
| 26 |
register: join_domain_check |
| 27 |
|
| 28 |
- name: get result of join domain - check mode |
| 29 |
ansible.windows.win_powershell: |
| 30 |
script: '{{ get_result_script }}' |
| 31 |
register: join_domain_check_actual |
| 32 |
|
| 33 |
- name: assert join domain - check mode |
| 34 |
assert: |
| 35 |
that: |
| 36 |
- join_domain_check is changed |
| 37 |
- join_domain_check.reboot_required == False |
| 38 |
- join_domain_check_actual.output[0]["DnsDomainName"] == None |
| 39 |
- join_domain_check_actual.output[0]["HostName"] == "TEST" |
| 40 |
- join_domain_check_actual.output[0]["NetbiosName"] == "TEST" |
| 41 |
- join_domain_check_actual.output[0]["PartOfDomain"] == False |
| 42 |
- join_domain_check_actual.output[0]["WorkgroupName"] == "WORKGROUP" |
| 43 |
|
| 44 |
- name: join domain with reboot |
| 45 |
membership: |
| 46 |
dns_domain_name: '{{ domain_realm }}' |
| 47 |
domain_admin_user: '{{ domain_user_upn }}' |
| 48 |
domain_admin_password: '{{ domain_password }}' |
| 49 |
state: domain |
| 50 |
reboot: true |
| 51 |
register: join_domain |
| 52 |
|
| 53 |
- name: get result of join domain with reboot |
| 54 |
ansible.windows.win_powershell: |
| 55 |
script: '{{ get_result_script }}' |
| 56 |
register: join_domain_actual |
| 57 |
|
| 58 |
- name: get ad result of join domain with reboot |
| 59 |
ansible.windows.win_powershell: |
| 60 |
script: '{{ get_ad_result_script }}' |
| 61 |
delegate_to: DC |
| 62 |
register: join_domain_ad_actual |
| 63 |
|
| 64 |
- name: assert join domain with reboot |
| 65 |
assert: |
| 66 |
that: |
| 67 |
- join_domain is changed |
| 68 |
- join_domain.reboot_required == False |
| 69 |
- join_domain_actual.output[0]["DnsDomainName"] == domain_realm |
| 70 |
- join_domain_actual.output[0]["HostName"] == "TEST" |
| 71 |
- join_domain_actual.output[0]["NetbiosName"] == "TEST" |
| 72 |
- join_domain_actual.output[0]["PartOfDomain"] == True |
| 73 |
- join_domain_actual.output[0]["WorkgroupName"] == None |
| 74 |
- join_domain_ad_actual.output | length == 1 |
| 75 |
- join_domain_ad_actual.output[0]["DNSHostName"] == "TEST" |
| 76 |
- join_domain_ad_actual.output[0]["Name"] == "TEST" |
| 77 |
- join_domain_ad_actual.output[0]["Enabled"] == True |
| 78 |
|
| 79 |
- name: join domain with reboot - idempotent |
| 80 |
membership: |
| 81 |
dns_domain_name: '{{ domain_realm }}' |
| 82 |
domain_admin_user: '{{ domain_user_upn }}' |
| 83 |
domain_admin_password: '{{ domain_password }}' |
| 84 |
state: domain |
| 85 |
reboot: true |
| 86 |
register: join_domain_again |
| 87 |
|
| 88 |
- name: assert join domain with reboot - idempotent |
| 89 |
assert: |
| 90 |
that: |
| 91 |
- not join_domain_again is changed |
| 92 |
- join_domain_again.reboot_required == False |
| 93 |
|
| 94 |
- name: fail to change domain of already joined host |
| 95 |
membership: |
| 96 |
dns_domain_name: fake.realm |
| 97 |
domain_admin_user: '{{ domain_user_upn }}' |
| 98 |
domain_admin_password: '{{ domain_password }}' |
| 99 |
state: domain |
| 100 |
reboot: true |
| 101 |
register: fail_cannot_rename_domain |
| 102 |
failed_when: |
| 103 |
- fail_cannot_rename_domain.msg != "Host is already joined to '" ~ domain_realm ~ "', switching domains is not implemented" |
| 104 |
|
| 105 |
- name: rename hostname of domain joined host - check mode |
| 106 |
membership: |
| 107 |
dns_domain_name: '{{ domain_realm }}' |
| 108 |
domain_admin_user: '{{ domain_user_upn }}' |
| 109 |
domain_admin_password: '{{ domain_password }}' |
| 110 |
hostname: TEST1-long-HOSTNAME1 |
| 111 |
state: domain |
| 112 |
reboot: true |
| 113 |
register: rename_host_domain_check |
| 114 |
check_mode: True |
| 115 |
|
| 116 |
- name: get result of rename hostname of domain joined host - check mode |
| 117 |
ansible.windows.win_powershell: |
| 118 |
script: '{{ get_result_script }}' |
| 119 |
register: rename_host_domain_check_actual |
| 120 |
|
| 121 |
- name: get ad result of rename hostname of domain joined host - check mode |
| 122 |
ansible.windows.win_powershell: |
| 123 |
script: '{{ get_ad_result_script }}' |
| 124 |
delegate_to: DC |
| 125 |
register: rename_host_domain_check_ad_actual |
| 126 |
|
| 127 |
- name: assert rename hostname of domain joined host - check mode |
| 128 |
assert: |
| 129 |
that: |
| 130 |
- rename_host_domain_check is changed |
| 131 |
- rename_host_domain_check.reboot_required == False |
| 132 |
- rename_host_domain_check_actual.output[0]["DnsDomainName"] == domain_realm |
| 133 |
- rename_host_domain_check_actual.output[0]["HostName"] == "TEST" |
| 134 |
- rename_host_domain_check_actual.output[0]["NetbiosName"] == "TEST" |
| 135 |
- rename_host_domain_check_actual.output[0]["PartOfDomain"] == True |
| 136 |
- rename_host_domain_check_actual.output[0]["WorkgroupName"] == None |
| 137 |
- rename_host_domain_check_ad_actual.output | length == 1 |
| 138 |
- rename_host_domain_check_ad_actual.output[0]["DNSHostName"] == "TEST" |
| 139 |
- rename_host_domain_check_ad_actual.output[0]["Name"] == "TEST" |
| 140 |
- rename_host_domain_check_ad_actual.output[0]["Enabled"] == True |
| 141 |
|
| 142 |
- name: rename hostname of domain joined host |
| 143 |
membership: |
| 144 |
dns_domain_name: '{{ domain_realm }}' |
| 145 |
domain_admin_user: '{{ domain_user_upn }}' |
| 146 |
domain_admin_password: '{{ domain_password }}' |
| 147 |
hostname: TEST1-long-HOSTNAME1 |
| 148 |
state: domain |
| 149 |
reboot: true |
| 150 |
register: rename_host_domain |
| 151 |
|
| 152 |
- name: get result of rename hostname of domain joined host |
| 153 |
ansible.windows.win_powershell: |
| 154 |
script: '{{ get_result_script }}' |
| 155 |
register: rename_host_domain_actual |
| 156 |
|
| 157 |
- name: get ad result of rename hostname of domain joined host |
| 158 |
ansible.windows.win_powershell: |
| 159 |
script: '{{ get_ad_result_script }}' |
| 160 |
delegate_to: DC |
| 161 |
register: rename_host_domain_ad_actual |
| 162 |
|
| 163 |
- name: assert rename hostname of domain joined host |
| 164 |
assert: |
| 165 |
that: |
| 166 |
- rename_host_domain is changed |
| 167 |
- rename_host_domain.reboot_required == False |
| 168 |
- rename_host_domain_actual.output[0]["DnsDomainName"] == domain_realm |
| 169 |
- rename_host_domain_actual.output[0]["HostName"] == "TEST1-long-HOSTNAME1" |
| 170 |
- rename_host_domain_actual.output[0]["NetbiosName"] == "TEST1-LONG-HOST" |
| 171 |
- rename_host_domain_actual.output[0]["PartOfDomain"] == True |
| 172 |
- rename_host_domain_actual.output[0]["WorkgroupName"] == None |
| 173 |
- rename_host_domain_ad_actual.output | length == 1 |
| 174 |
- rename_host_domain_ad_actual.output[0]["DNSHostName"] == "TEST1-long-HOSTNAME1" |
| 175 |
- rename_host_domain_ad_actual.output[0]["Name"] == "TEST1-LONG-HOST" |
| 176 |
- rename_host_domain_ad_actual.output[0]["Enabled"] == True |
| 177 |
|
| 178 |
- name: rename hostname of domain joined host - idempotent |
| 179 |
membership: |
| 180 |
dns_domain_name: '{{ domain_realm }}' |
| 181 |
domain_admin_user: '{{ domain_user_upn }}' |
| 182 |
domain_admin_password: '{{ domain_password }}' |
| 183 |
hostname: TEST1-long-HOSTNAME1 |
| 184 |
state: domain |
| 185 |
reboot: true |
| 186 |
register: rename_host_domain_again |
| 187 |
|
| 188 |
- name: assert rename hostname of domain joined host - idempotent |
| 189 |
assert: |
| 190 |
that: |
| 191 |
- not rename_host_domain_again is changed |
| 192 |
|
| 193 |
- name: rename hostname of domain joined host netbios portion - check mode |
| 194 |
membership: |
| 195 |
dns_domain_name: '{{ domain_realm }}' |
| 196 |
domain_admin_user: '{{ domain_user_upn }}' |
| 197 |
domain_admin_password: '{{ domain_password }}' |
| 198 |
hostname: TEST2-long-HOSTNAME1 |
| 199 |
state: domain |
| 200 |
reboot: true |
| 201 |
register: rename_host_domain_netbios_check |
| 202 |
check_mode: True |
| 203 |
|
| 204 |
- name: get result of rename hostname of domain joined host netbios portion - check mode |
| 205 |
ansible.windows.win_powershell: |
| 206 |
script: '{{ get_result_script }}' |
| 207 |
register: rename_host_domain_netbios_check_actual |
| 208 |
|
| 209 |
- name: get ad result of rename hostname of domain joined host netbios portion - check mode |
| 210 |
ansible.windows.win_powershell: |
| 211 |
script: '{{ get_ad_result_script }}' |
| 212 |
delegate_to: DC |
| 213 |
register: rename_host_domain_netbios_check_ad_actual |
| 214 |
|
| 215 |
- name: assert rename hostname of domain joined host netbios portion - check mode |
| 216 |
assert: |
| 217 |
that: |
| 218 |
- rename_host_domain_netbios_check is changed |
| 219 |
- rename_host_domain_netbios_check.reboot_required == False |
| 220 |
- rename_host_domain_netbios_check_actual.output[0]["DnsDomainName"] == domain_realm |
| 221 |
- rename_host_domain_netbios_check_actual.output[0]["HostName"] == "TEST1-long-HOSTNAME1" |
| 222 |
- rename_host_domain_netbios_check_actual.output[0]["NetbiosName"] == "TEST1-LONG-HOST" |
| 223 |
- rename_host_domain_netbios_check_actual.output[0]["PartOfDomain"] == True |
| 224 |
- rename_host_domain_netbios_check_actual.output[0]["WorkgroupName"] == None |
| 225 |
- rename_host_domain_netbios_check_ad_actual.output | length == 1 |
| 226 |
- rename_host_domain_netbios_check_ad_actual.output[0]["DNSHostName"] == "TEST1-long-HOSTNAME1" |
| 227 |
- rename_host_domain_netbios_check_ad_actual.output[0]["Name"] == "TEST1-LONG-HOST" |
| 228 |
- rename_host_domain_netbios_check_ad_actual.output[0]["Enabled"] == True |
| 229 |
|
| 230 |
- name: rename hostname of domain joined host netbios portion |
| 231 |
membership: |
| 232 |
dns_domain_name: '{{ domain_realm }}' |
| 233 |
domain_admin_user: '{{ domain_user_upn }}' |
| 234 |
domain_admin_password: '{{ domain_password }}' |
| 235 |
hostname: TEST2-long-HOSTNAME1 |
| 236 |
state: domain |
| 237 |
reboot: true |
| 238 |
register: rename_host_domain_netbios |
| 239 |
|
| 240 |
- name: get result of rename hostname of domain joined host netbios portion |
| 241 |
ansible.windows.win_powershell: |
| 242 |
script: '{{ get_result_script }}' |
| 243 |
register: rename_host_domain_netbios_actual |
| 244 |
|
| 245 |
- name: get ad result of rename hostname of domain joined host netbios portion |
| 246 |
ansible.windows.win_powershell: |
| 247 |
script: '{{ get_ad_result_script }}' |
| 248 |
delegate_to: DC |
| 249 |
register: rename_host_domain_netbios_ad_actual |
| 250 |
|
| 251 |
- name: assert rename hostname of domain joined host |
| 252 |
assert: |
| 253 |
that: |
| 254 |
- rename_host_domain_netbios is changed |
| 255 |
- rename_host_domain_netbios.reboot_required == False |
| 256 |
- rename_host_domain_netbios_actual.output[0]["DnsDomainName"] == domain_realm |
| 257 |
- rename_host_domain_netbios_actual.output[0]["HostName"] == "TEST2-long-HOSTNAME1" |
| 258 |
- rename_host_domain_netbios_actual.output[0]["NetbiosName"] == "TEST2-LONG-HOST" |
| 259 |
- rename_host_domain_netbios_actual.output[0]["PartOfDomain"] == True |
| 260 |
- rename_host_domain_netbios_actual.output[0]["WorkgroupName"] == None |
| 261 |
- rename_host_domain_netbios_ad_actual.output | length == 1 |
| 262 |
- rename_host_domain_netbios_ad_actual.output[0]["DNSHostName"] == "TEST2-long-HOSTNAME1" |
| 263 |
- rename_host_domain_netbios_ad_actual.output[0]["Name"] == "TEST2-LONG-HOST" |
| 264 |
- rename_host_domain_netbios_ad_actual.output[0]["Enabled"] == True |
| 265 |
|
| 266 |
- name: change domain to workgroup - check mode |
| 267 |
membership: |
| 268 |
workgroup_name: TEST |
| 269 |
domain_admin_user: '{{ domain_user_upn }}' |
| 270 |
domain_admin_password: '{{ domain_password }}' |
| 271 |
state: workgroup |
| 272 |
register: to_workgroup_check |
| 273 |
check_mode: true |
| 274 |
|
| 275 |
- name: get result of change domain to workgroup - check mode |
| 276 |
ansible.windows.win_powershell: |
| 277 |
script: '{{ get_result_script }}' |
| 278 |
register: to_workgroup_check_actual |
| 279 |
|
| 280 |
- name: get ad result of change domain to workgroup - check mode |
| 281 |
ansible.windows.win_powershell: |
| 282 |
script: '{{ get_ad_result_script }}' |
| 283 |
delegate_to: DC |
| 284 |
register: to_workgroup_check_ad_actual |
| 285 |
|
| 286 |
- name: assert change domain to workgroup - check mode |
| 287 |
assert: |
| 288 |
that: |
| 289 |
- to_workgroup_check is changed |
| 290 |
- to_workgroup_check.reboot_required == True |
| 291 |
- to_workgroup_check_actual.output[0]["DnsDomainName"] == domain_realm |
| 292 |
- to_workgroup_check_actual.output[0]["HostName"] == "TEST2-long-HOSTNAME1" |
| 293 |
- to_workgroup_check_actual.output[0]["NetbiosName"] == "TEST2-LONG-HOST" |
| 294 |
- to_workgroup_check_actual.output[0]["PartOfDomain"] == True |
| 295 |
- to_workgroup_check_actual.output[0]["WorkgroupName"] == None |
| 296 |
- to_workgroup_check_ad_actual.output | length == 1 |
| 297 |
- to_workgroup_check_ad_actual.output[0]["DNSHostName"] == "TEST2-long-HOSTNAME1" |
| 298 |
- to_workgroup_check_ad_actual.output[0]["Name"] == "TEST2-LONG-HOST" |
| 299 |
- to_workgroup_check_ad_actual.output[0]["Enabled"] == True |
| 300 |
|
| 301 |
- name: change domain to workgroup |
| 302 |
membership: |
| 303 |
workgroup_name: TEST |
| 304 |
domain_admin_user: '{{ domain_user_upn }}' |
| 305 |
domain_admin_password: '{{ domain_password }}' |
| 306 |
state: workgroup |
| 307 |
register: to_workgroup |
| 308 |
|
| 309 |
- set_fact: |
| 310 |
local_user: TEST2-LONG-HOST\{{ ansible_user }} |
| 311 |
|
| 312 |
- ansible.windows.win_reboot: |
| 313 |
when: to_workgroup.reboot_required |
| 314 |
vars: |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
ansible_user: '{{ local_user }}' |
| 320 |
|
| 321 |
- name: get result of change domain to workgroup |
| 322 |
ansible.windows.win_powershell: |
| 323 |
script: '{{ get_result_script }}' |
| 324 |
register: to_workgroup_actual |
| 325 |
|
| 326 |
- name: get ad result of change domain to workgroup |
| 327 |
ansible.windows.win_powershell: |
| 328 |
script: '{{ get_ad_result_script }}' |
| 329 |
delegate_to: DC |
| 330 |
register: to_workgroup_ad_actual |
| 331 |
|
| 332 |
- name: assert change domain to workgroup |
| 333 |
assert: |
| 334 |
that: |
| 335 |
- to_workgroup is changed |
| 336 |
- to_workgroup.reboot_required == True |
| 337 |
- to_workgroup_actual.output[0]["DnsDomainName"] == None |
| 338 |
- to_workgroup_actual.output[0]["HostName"] == "TEST2-long-HOSTNAME1" |
| 339 |
- to_workgroup_actual.output[0]["NetbiosName"] == "TEST2-LONG-HOST" |
| 340 |
- to_workgroup_actual.output[0]["PartOfDomain"] == False |
| 341 |
- to_workgroup_actual.output[0]["WorkgroupName"] == "TEST" |
| 342 |
- to_workgroup_ad_actual.output | length == 1 |
| 343 |
- to_workgroup_ad_actual.output[0]["DNSHostName"] == "TEST2-long-HOSTNAME1" |
| 344 |
- to_workgroup_ad_actual.output[0]["Name"] == "TEST2-LONG-HOST" |
| 345 |
- to_workgroup_ad_actual.output[0]["Enabled"] == False |
| 346 |
|
| 347 |
- name: remove orphaned AD account for later tests |
| 348 |
microsoft.ad.computer: |
| 349 |
name: TEST2-LONG-HOST |
| 350 |
state: absent |
| 351 |
delegate_to: DC |
| 352 |
|
| 353 |
- name: change domain to workgroup - idempotent |
| 354 |
membership: |
| 355 |
workgroup_name: TEST |
| 356 |
domain_admin_user: '{{ domain_user_upn }}' |
| 357 |
domain_admin_password: '{{ domain_password }}' |
| 358 |
state: workgroup |
| 359 |
reboot: true |
| 360 |
register: to_workgroup_again |
| 361 |
|
| 362 |
- name: assert change domain to workgroup - idempotent |
| 363 |
assert: |
| 364 |
that: |
| 365 |
- not to_workgroup_again is changed |
| 366 |
- to_workgroup_again.reboot_required == False |
| 367 |
|
| 368 |
- name: change workgroup - check mode |
| 369 |
membership: |
| 370 |
workgroup_name: TEST2 |
| 371 |
domain_admin_user: '{{ domain_user_upn }}' |
| 372 |
domain_admin_password: '{{ domain_password }}' |
| 373 |
state: workgroup |
| 374 |
reboot: true |
| 375 |
register: change_workgroup_check |
| 376 |
check_mode: true |
| 377 |
|
| 378 |
- name: get result of change workgroup - check mode |
| 379 |
ansible.windows.win_powershell: |
| 380 |
script: '{{ get_result_script }}' |
| 381 |
register: change_workgroup_check_actual |
| 382 |
|
| 383 |
- name: assert change workgroup - check mode |
| 384 |
assert: |
| 385 |
that: |
| 386 |
- change_workgroup_check is changed |
| 387 |
- change_workgroup_check.reboot_required == False |
| 388 |
- change_workgroup_check_actual.output[0]["DnsDomainName"] == None |
| 389 |
- change_workgroup_check_actual.output[0]["HostName"] == "TEST2-long-HOSTNAME1" |
| 390 |
- change_workgroup_check_actual.output[0]["NetbiosName"] == "TEST2-LONG-HOST" |
| 391 |
- change_workgroup_check_actual.output[0]["PartOfDomain"] == False |
| 392 |
- change_workgroup_check_actual.output[0]["WorkgroupName"] == "TEST" |
| 393 |
|
| 394 |
- name: change workgroup |
| 395 |
membership: |
| 396 |
workgroup_name: TEST2 |
| 397 |
domain_admin_user: '{{ domain_user_upn }}' |
| 398 |
domain_admin_password: '{{ domain_password }}' |
| 399 |
state: workgroup |
| 400 |
reboot: true |
| 401 |
register: change_workgroup |
| 402 |
|
| 403 |
- name: get result of change workgroup |
| 404 |
ansible.windows.win_powershell: |
| 405 |
script: '{{ get_result_script }}' |
| 406 |
register: change_workgroup_actual |
| 407 |
|
| 408 |
- name: assert change workgroup |
| 409 |
assert: |
| 410 |
that: |
| 411 |
- change_workgroup is changed |
| 412 |
- change_workgroup.reboot_required == False |
| 413 |
- change_workgroup_actual.output[0]["DnsDomainName"] == None |
| 414 |
- change_workgroup_actual.output[0]["HostName"] == "TEST2-long-HOSTNAME1" |
| 415 |
- change_workgroup_actual.output[0]["NetbiosName"] == "TEST2-LONG-HOST" |
| 416 |
- change_workgroup_actual.output[0]["PartOfDomain"] == False |
| 417 |
- change_workgroup_actual.output[0]["WorkgroupName"] == "TEST2" |
| 418 |
|
| 419 |
- name: change just the hostname - check mode |
| 420 |
membership: |
| 421 |
workgroup_name: TEST2 |
| 422 |
domain_admin_user: '{{ domain_user_upn }}' |
| 423 |
domain_admin_password: '{{ domain_password }}' |
| 424 |
state: workgroup |
| 425 |
reboot: true |
| 426 |
hostname: TEST1-long-HOSTNAME2 |
| 427 |
register: change_hostname_check |
| 428 |
check_mode: true |
| 429 |
|
| 430 |
- name: get result of change just the hostname - check mode |
| 431 |
ansible.windows.win_powershell: |
| 432 |
script: '{{ get_result_script }}' |
| 433 |
register: change_hostname_check_actual |
| 434 |
|
| 435 |
- name: assert change just the hostname - check mode |
| 436 |
assert: |
| 437 |
that: |
| 438 |
- change_hostname_check is changed |
| 439 |
- change_hostname_check.reboot_required == False |
| 440 |
- change_hostname_check_actual.output[0]["DnsDomainName"] == None |
| 441 |
- change_hostname_check_actual.output[0]["HostName"] == "TEST2-long-HOSTNAME1" |
| 442 |
- change_hostname_check_actual.output[0]["NetbiosName"] == "TEST2-LONG-HOST" |
| 443 |
- change_hostname_check_actual.output[0]["PartOfDomain"] == False |
| 444 |
- change_hostname_check_actual.output[0]["WorkgroupName"] == "TEST2" |
| 445 |
|
| 446 |
- name: change just the hostname |
| 447 |
membership: |
| 448 |
workgroup_name: TEST2 |
| 449 |
domain_admin_user: '{{ domain_user_upn }}' |
| 450 |
domain_admin_password: '{{ domain_password }}' |
| 451 |
state: workgroup |
| 452 |
reboot: true |
| 453 |
hostname: TEST1-long-HOSTNAME2 |
| 454 |
register: change_hostname |
| 455 |
|
| 456 |
- name: get result of change just the hostname |
| 457 |
ansible.windows.win_powershell: |
| 458 |
script: '{{ get_result_script }}' |
| 459 |
register: change_hostname_actual |
| 460 |
|
| 461 |
- name: assert change just the hostname |
| 462 |
assert: |
| 463 |
that: |
| 464 |
- change_hostname is changed |
| 465 |
- change_hostname.reboot_required == False |
| 466 |
- change_hostname_actual.output[0]["DnsDomainName"] == None |
| 467 |
- change_hostname_actual.output[0]["HostName"] == "TEST1-long-HOSTNAME2" |
| 468 |
- change_hostname_actual.output[0]["NetbiosName"] == "TEST1-LONG-HOST" |
| 469 |
- change_hostname_actual.output[0]["PartOfDomain"] == False |
| 470 |
- change_hostname_actual.output[0]["WorkgroupName"] == "TEST2" |
| 471 |
|
| 472 |
- name: change just the hostname - idempotent |
| 473 |
membership: |
| 474 |
workgroup_name: TEST2 |
| 475 |
domain_admin_user: '{{ domain_user_upn }}' |
| 476 |
domain_admin_password: '{{ domain_password }}' |
| 477 |
state: workgroup |
| 478 |
reboot: true |
| 479 |
hostname: TEST1-long-HOSTNAME2 |
| 480 |
register: change_hostname_again |
| 481 |
|
| 482 |
- name: assert change just the hostname - idempotent |
| 483 |
assert: |
| 484 |
that: |
| 485 |
- not change_hostname_again is changed |
| 486 |
|
| 487 |
- name: change just the hostname netbios portion - check mode |
| 488 |
membership: |
| 489 |
workgroup_name: TEST2 |
| 490 |
domain_admin_user: '{{ domain_user_upn }}' |
| 491 |
domain_admin_password: '{{ domain_password }}' |
| 492 |
state: workgroup |
| 493 |
reboot: true |
| 494 |
hostname: TEST2-long-HOSTNAME2 |
| 495 |
register: change_hostname_netbios_check |
| 496 |
check_mode: true |
| 497 |
|
| 498 |
- name: get result of change just the hostname netbios portion - check mode |
| 499 |
ansible.windows.win_powershell: |
| 500 |
script: '{{ get_result_script }}' |
| 501 |
register: change_hostname_netbios_check_actual |
| 502 |
|
| 503 |
- name: assert change just the hostname netbios portion - check mode |
| 504 |
assert: |
| 505 |
that: |
| 506 |
- change_hostname_netbios_check is changed |
| 507 |
- change_hostname_netbios_check.reboot_required == False |
| 508 |
- change_hostname_netbios_check_actual.output[0]["DnsDomainName"] == None |
| 509 |
- change_hostname_netbios_check_actual.output[0]["HostName"] == "TEST1-long-HOSTNAME2" |
| 510 |
- change_hostname_netbios_check_actual.output[0]["NetbiosName"] == "TEST1-LONG-HOST" |
| 511 |
- change_hostname_netbios_check_actual.output[0]["PartOfDomain"] == False |
| 512 |
- change_hostname_netbios_check_actual.output[0]["WorkgroupName"] == "TEST2" |
| 513 |
|
| 514 |
- name: change just the hostname netbios portion |
| 515 |
membership: |
| 516 |
workgroup_name: TEST2 |
| 517 |
domain_admin_user: '{{ domain_user_upn }}' |
| 518 |
domain_admin_password: '{{ domain_password }}' |
| 519 |
state: workgroup |
| 520 |
reboot: true |
| 521 |
hostname: TEST2-long-HOSTNAME2 |
| 522 |
register: change_hostname_netbios |
| 523 |
|
| 524 |
- name: get result of change just the hostname netbios portion |
| 525 |
ansible.windows.win_powershell: |
| 526 |
script: '{{ get_result_script }}' |
| 527 |
register: change_hostname_netbios_actual |
| 528 |
|
| 529 |
- name: assert change just the hostname |
| 530 |
assert: |
| 531 |
that: |
| 532 |
- change_hostname_netbios is changed |
| 533 |
- change_hostname_netbios.reboot_required == False |
| 534 |
- change_hostname_netbios_actual.output[0]["DnsDomainName"] == None |
| 535 |
- change_hostname_netbios_actual.output[0]["HostName"] == "TEST2-long-HOSTNAME2" |
| 536 |
- change_hostname_netbios_actual.output[0]["NetbiosName"] == "TEST2-LONG-HOST" |
| 537 |
- change_hostname_netbios_actual.output[0]["PartOfDomain"] == False |
| 538 |
- change_hostname_netbios_actual.output[0]["WorkgroupName"] == "TEST2" |
| 539 |
|
| 540 |
- name: create custom OU |
| 541 |
ansible.windows.win_powershell: |
| 542 |
script: | |
| 543 |
$ou = New-ADOrganizationalUnit -Name MyHosts -PassThru |
| 544 |
$ou.DistinguishedName |
| 545 |
delegate_to: DC |
| 546 |
register: custom_ou |
| 547 |
|
| 548 |
- name: join domain with hostname and OU - check mode |
| 549 |
membership: |
| 550 |
dns_domain_name: '{{ domain_realm }}' |
| 551 |
domain_admin_user: '{{ domain_user_upn }}' |
| 552 |
domain_admin_password: '{{ domain_password }}' |
| 553 |
hostname: TEST1-long-HOSTNAME3 |
| 554 |
domain_ou_path: '{{ custom_ou.output[0] }}' |
| 555 |
state: domain |
| 556 |
register: join_ou_check |
| 557 |
check_mode: true |
| 558 |
|
| 559 |
- name: get result of join domain with hostname and OU - check mode |
| 560 |
ansible.windows.win_powershell: |
| 561 |
script: '{{ get_result_script }}' |
| 562 |
register: join_ou_check_actual |
| 563 |
|
| 564 |
- name: assert change just the hostname - check mode |
| 565 |
assert: |
| 566 |
that: |
| 567 |
- join_ou_check is changed |
| 568 |
- join_ou_check.reboot_required == True |
| 569 |
- join_ou_check_actual.output[0]["DnsDomainName"] == None |
| 570 |
- join_ou_check_actual.output[0]["HostName"] == "TEST2-long-HOSTNAME2" |
| 571 |
- join_ou_check_actual.output[0]["NetbiosName"] == "TEST2-LONG-HOST" |
| 572 |
- join_ou_check_actual.output[0]["PartOfDomain"] == False |
| 573 |
- join_ou_check_actual.output[0]["WorkgroupName"] == "TEST2" |
| 574 |
|
| 575 |
- name: join domain with hostname and OU |
| 576 |
membership: |
| 577 |
dns_domain_name: '{{ domain_realm }}' |
| 578 |
domain_admin_user: '{{ domain_user_upn }}' |
| 579 |
domain_admin_password: '{{ domain_password }}' |
| 580 |
hostname: TEST1-long-HOSTNAME3 |
| 581 |
domain_ou_path: '{{ custom_ou.output[0] }}' |
| 582 |
state: domain |
| 583 |
register: join_ou |
| 584 |
|
| 585 |
- ansible.windows.win_reboot: |
| 586 |
when: join_ou.reboot_required |
| 587 |
|
| 588 |
- name: get result of join domain with hostname and OU |
| 589 |
ansible.windows.win_powershell: |
| 590 |
script: '{{ get_result_script }}' |
| 591 |
register: join_ou_actual |
| 592 |
|
| 593 |
- name: get ad result of join domain with hostname and OU |
| 594 |
ansible.windows.win_powershell: |
| 595 |
script: '{{ get_ad_result_script }}' |
| 596 |
register: join_ou_ad_actual |
| 597 |
delegate_to: DC |
| 598 |
|
| 599 |
- name: assert join domain with hostname and OU |
| 600 |
assert: |
| 601 |
that: |
| 602 |
- join_ou is changed |
| 603 |
- join_ou.reboot_required == True |
| 604 |
- join_ou_actual.output[0]["DnsDomainName"] == domain_realm |
| 605 |
- join_ou_actual.output[0]["HostName"] == "TEST1-long-HOSTNAME3" |
| 606 |
- join_ou_actual.output[0]["NetbiosName"] == "TEST1-LONG-HOST" |
| 607 |
- join_ou_actual.output[0]["PartOfDomain"] == True |
| 608 |
- join_ou_actual.output[0]["WorkgroupName"] == None |
| 609 |
- join_ou_ad_actual.output | length == 1 |
| 610 |
- join_ou_ad_actual.output[0]["DNSHostName"] == "TEST1-long-HOSTNAME3" |
| 611 |
- join_ou_ad_actual.output[0]["Name"] == "TEST1-LONG-HOST" |
| 612 |
- join_ou_ad_actual.output[0]["Enabled"] == True |
| 613 |
- join_ou_ad_actual.output[0]["DistinguishedName"] == "CN=TEST1-LONG-HOST," ~ custom_ou.output[0] |
| 614 |
|
| 615 |
- name: change domain to workgroup with hostname change - check mode |
| 616 |
membership: |
| 617 |
workgroup_name: WORKGROUP |
| 618 |
domain_admin_user: '{{ domain_user_upn }}' |
| 619 |
domain_admin_password: '{{ domain_password }}' |
| 620 |
hostname: TEST1-long-HOSTNAME4 |
| 621 |
state: workgroup |
| 622 |
register: to_workgroup_hostname_check |
| 623 |
check_mode: true |
| 624 |
|
| 625 |
- name: get result of change domain to workgroup with hostname change - check mode |
| 626 |
ansible.windows.win_powershell: |
| 627 |
script: '{{ get_result_script }}' |
| 628 |
register: to_workgroup_hostname_check_actual |
| 629 |
|
| 630 |
- name: get ad result of change domain to workgroup with hostname change - check mode |
| 631 |
ansible.windows.win_powershell: |
| 632 |
script: '{{ get_ad_result_script }}' |
| 633 |
delegate_to: DC |
| 634 |
register: to_workgroup_hostname_check_ad_actual |
| 635 |
|
| 636 |
- name: assert change domain to workgroup with hostname change - check mode |
| 637 |
assert: |
| 638 |
that: |
| 639 |
- to_workgroup_hostname_check is changed |
| 640 |
- to_workgroup_hostname_check.reboot_required == True |
| 641 |
- to_workgroup_hostname_check_actual.output[0]["DnsDomainName"] == domain_realm |
| 642 |
- to_workgroup_hostname_check_actual.output[0]["HostName"] == "TEST1-long-HOSTNAME3" |
| 643 |
- to_workgroup_hostname_check_actual.output[0]["NetbiosName"] == "TEST1-LONG-HOST" |
| 644 |
- to_workgroup_hostname_check_actual.output[0]["PartOfDomain"] == True |
| 645 |
- to_workgroup_hostname_check_actual.output[0]["WorkgroupName"] == None |
| 646 |
- to_workgroup_hostname_check_ad_actual.output | length == 1 |
| 647 |
- to_workgroup_hostname_check_ad_actual.output[0]["DNSHostName"] == "TEST1-long-HOSTNAME3" |
| 648 |
- to_workgroup_hostname_check_ad_actual.output[0]["Name"] == "TEST1-LONG-HOST" |
| 649 |
- to_workgroup_hostname_check_ad_actual.output[0]["Enabled"] == True |
| 650 |
|
| 651 |
- name: change domain to workgroup with hostname change |
| 652 |
membership: |
| 653 |
workgroup_name: WORKGROUP |
| 654 |
domain_admin_user: '{{ domain_user_upn }}' |
| 655 |
domain_admin_password: '{{ domain_password }}' |
| 656 |
hostname: TEST1-long-HOSTNAME4 |
| 657 |
state: workgroup |
| 658 |
reboot: true |
| 659 |
register: to_workgroup_hostname |
| 660 |
|
| 661 |
- name: get result of change domain to workgroup with hostname change |
| 662 |
ansible.windows.win_powershell: |
| 663 |
script: '{{ get_result_script }}' |
| 664 |
register: to_workgroup_hostname_actual |
| 665 |
|
| 666 |
- name: get ad result of change domain to workgroup with hostname change |
| 667 |
ansible.windows.win_powershell: |
| 668 |
script: '{{ get_ad_result_script }}' |
| 669 |
delegate_to: DC |
| 670 |
register: to_workgroup_hostname_ad_actual |
| 671 |
|
| 672 |
- name: assert change domain to workgroup with hostname change |
| 673 |
assert: |
| 674 |
that: |
| 675 |
- to_workgroup_hostname is changed |
| 676 |
- to_workgroup_hostname.reboot_required == False |
| 677 |
- to_workgroup_hostname_actual.output[0]["DnsDomainName"] == None |
| 678 |
- to_workgroup_hostname_actual.output[0]["HostName"] == "TEST1-long-HOSTNAME4" |
| 679 |
- to_workgroup_hostname_actual.output[0]["NetbiosName"] == "TEST1-LONG-HOST" |
| 680 |
- to_workgroup_hostname_actual.output[0]["PartOfDomain"] == False |
| 681 |
- to_workgroup_hostname_actual.output[0]["WorkgroupName"] == "WORKGROUP" |
| 682 |
- to_workgroup_hostname_ad_actual.output | length == 1 |
| 683 |
- to_workgroup_hostname_ad_actual.output[0]["DNSHostName"] == "TEST1-long-HOSTNAME3" |
| 684 |
- to_workgroup_hostname_ad_actual.output[0]["Name"] == "TEST1-LONG-HOST" |
| 685 |
- to_workgroup_hostname_ad_actual.output[0]["Enabled"] == False |
| 686 |
|
| 687 |
- name: change domain to workgroup with hostname change - idempotent |
| 688 |
membership: |
| 689 |
workgroup_name: WORKGROUP |
| 690 |
domain_admin_user: '{{ domain_user_upn }}' |
| 691 |
domain_admin_password: '{{ domain_password }}' |
| 692 |
hostname: TEST1-long-HOSTNAME4 |
| 693 |
state: workgroup |
| 694 |
reboot: true |
| 695 |
register: to_workgroup_hostname_again |
| 696 |
|
| 697 |
- name: assert change domain to workgroup with hostname change - idempotent |
| 698 |
assert: |
| 699 |
that: |
| 700 |
- not to_workgroup_hostname_again is changed |
| 701 |
|
| 702 |
- name: remove orphaned AD account for later tests |
| 703 |
microsoft.ad.computer: |
| 704 |
name: TEST1-LONG-HOST |
| 705 |
path: '{{ custom_ou.output[0] }}' |
| 706 |
state: absent |
| 707 |
delegate_to: DC |
| 708 |
|
| 709 |
- name: create computer object |
| 710 |
microsoft.ad.computer: |
| 711 |
name: My, Computer |
| 712 |
path: CN=Users,{{ domain_dn_base }} |
| 713 |
sam_account_name: MyComp$ |
| 714 |
state: present |
| 715 |
delegate_to: DC |
| 716 |
register: comp_account |
| 717 |
|
| 718 |
- name: get offline join blob |
| 719 |
microsoft.ad.offline_join: |
| 720 |
identity: '{{ comp_account.object_guid }}' |
| 721 |
delegate_to: DC |
| 722 |
register: offline_join |
| 723 |
|
| 724 |
- name: get computer object info |
| 725 |
microsoft.ad.object_info: |
| 726 |
identity: '{{ comp_account.object_guid }}' |
| 727 |
properties: |
| 728 |
- pwdLastSet |
| 729 |
delegate_to: DC |
| 730 |
register: comp_account_pre_join |
| 731 |
|
| 732 |
- name: join domain by offline blob - check |
| 733 |
microsoft.ad.membership: |
| 734 |
offline_join_blob: '{{ offline_join.blob }}' |
| 735 |
state: domain |
| 736 |
register: offline_join_check |
| 737 |
check_mode: true |
| 738 |
|
| 739 |
- name: get result of join domain by offline blob - check |
| 740 |
ansible.windows.win_powershell: |
| 741 |
script: '{{ get_result_script }}' |
| 742 |
register: offline_join_check_actual |
| 743 |
|
| 744 |
- name: get result of join domain by offline blob comp info - check |
| 745 |
microsoft.ad.object_info: |
| 746 |
identity: '{{ comp_account.object_guid }}' |
| 747 |
properties: |
| 748 |
- pwdLastSet |
| 749 |
delegate_to: DC |
| 750 |
register: offline_join_check_ad_actual |
| 751 |
|
| 752 |
- name: assert join domain by offline blob - check |
| 753 |
assert: |
| 754 |
that: |
| 755 |
- offline_join_check is changed |
| 756 |
- offline_join_check.reboot_required == true |
| 757 |
- offline_join_check_actual.output[0].DnsDomainName == None |
| 758 |
- offline_join_check_actual.output[0].PartOfDomain == False |
| 759 |
- offline_join_check_ad_actual.objects[0].pwdLastSet == comp_account_pre_join.objects[0].pwdLastSet |
| 760 |
|
| 761 |
- name: join domain by offline blob |
| 762 |
microsoft.ad.membership: |
| 763 |
offline_join_blob: '{{ offline_join.blob }}' |
| 764 |
state: domain |
| 765 |
reboot: true |
| 766 |
register: offline_join_res |
| 767 |
|
| 768 |
- name: get result of join domain by offline blob |
| 769 |
ansible.windows.win_powershell: |
| 770 |
script: '{{ get_result_script }}' |
| 771 |
register: offline_join_actual |
| 772 |
|
| 773 |
- name: get result of join domain by offline blob comp info |
| 774 |
microsoft.ad.object_info: |
| 775 |
identity: '{{ comp_account.object_guid }}' |
| 776 |
properties: |
| 777 |
- pwdLastSet |
| 778 |
delegate_to: DC |
| 779 |
register: offline_join_ad_actual |
| 780 |
|
| 781 |
- name: assert join domain by offline blob |
| 782 |
assert: |
| 783 |
that: |
| 784 |
- offline_join_res is changed |
| 785 |
- offline_join_res.reboot_required == false |
| 786 |
- offline_join_actual.output[0].DnsDomainName == domain_realm |
| 787 |
- offline_join_actual.output[0].PartOfDomain == True |
| 788 |
- offline_join_ad_actual.objects[0].pwdLastSet > offline_join_check_ad_actual.objects[0].pwdLastSet |
| 789 |
|
| 790 |
- name: join domain by offline blob - idempotent |
| 791 |
microsoft.ad.membership: |
| 792 |
offline_join_blob: '{{ offline_join.blob }}' |
| 793 |
state: domain |
| 794 |
register: offline_join_again |
| 795 |
|
| 796 |
- name: assert join domain by offline blob - idempotent |
| 797 |
assert: |
| 798 |
that: |
| 799 |
- not offline_join_again is changed |
| 800 |
|
| 801 |
- name: change domain to workgroup |
| 802 |
membership: |
| 803 |
workgroup_name: WORKGROUP |
| 804 |
domain_admin_user: '{{ domain_user_upn }}' |
| 805 |
domain_admin_password: '{{ domain_password }}' |
| 806 |
state: workgroup |
| 807 |
reboot: true |
| 808 |
|
| 809 |
- name: remove orphaned AD account for later tests |
| 810 |
microsoft.ad.computer: |
| 811 |
name: My, Computer |
| 812 |
path: CN=Users,{{ domain_dn_base }} |
| 813 |
state: absent |
| 814 |
delegate_to: DC |