| 1 |
- name: create test object in parent domain with domain_username creds - check mode |
| 2 |
microsoft.ad.user: |
| 3 |
name: ParentUser1 |
| 4 |
path: '{{ parent_ou }}' |
| 5 |
state: present |
| 6 |
password: '{{ domain_password }}' |
| 7 |
update_password: when_changed |
| 8 |
domain_server: '{{ domain_realm }}' |
| 9 |
domain_username: '{{ domain_user_upn }}' |
| 10 |
domain_password: '{{ domain_password }}' |
| 11 |
register: user_with_creds1_check |
| 12 |
check_mode: true |
| 13 |
delegate_to: CHILD |
| 14 |
|
| 15 |
- name: get result of create test object in parent domain with domain_username creds - check mode |
| 16 |
microsoft.ad.object_info: |
| 17 |
identity: CN=ParentUser1,{{ parent_ou }} |
| 18 |
register: user_with_creds1_check_actual |
| 19 |
delegate_to: PARENT |
| 20 |
|
| 21 |
- name: assert create test object in parent domain with domain_username creds - check mode |
| 22 |
assert: |
| 23 |
that: |
| 24 |
- user_with_creds1_check is changed |
| 25 |
- user_with_creds1_check.distinguished_name == "CN=ParentUser1," ~ parent_ou |
| 26 |
- user_with_creds1_check_actual.objects == [] |
| 27 |
|
| 28 |
- name: create test object in parent domain with domain_username creds |
| 29 |
microsoft.ad.user: |
| 30 |
name: ParentUser1 |
| 31 |
path: '{{ parent_ou }}' |
| 32 |
state: present |
| 33 |
password: '{{ domain_password }}' |
| 34 |
update_password: when_changed |
| 35 |
domain_server: '{{ domain_realm }}' |
| 36 |
domain_username: '{{ domain_user_upn }}' |
| 37 |
domain_password: '{{ domain_password }}' |
| 38 |
register: user_with_creds1 |
| 39 |
delegate_to: CHILD |
| 40 |
|
| 41 |
- name: get result of create test object in parent domain with domain_username creds |
| 42 |
microsoft.ad.object_info: |
| 43 |
identity: CN=ParentUser1,{{ parent_ou }} |
| 44 |
register: user_with_creds1_actual |
| 45 |
delegate_to: PARENT |
| 46 |
|
| 47 |
- name: assert create test object in parent domain with domain_username creds |
| 48 |
assert: |
| 49 |
that: |
| 50 |
- user_with_creds1 is changed |
| 51 |
- user_with_creds1.distinguished_name == "CN=ParentUser1," ~ parent_ou |
| 52 |
- user_with_creds1_actual.objects | count == 1 |
| 53 |
- user_with_creds1_actual.objects[0].ObjectGUID == user_with_creds1.object_guid |
| 54 |
- user_with_creds1_actual.objects[0].DistinguishedName == user_with_creds1.distinguished_name |
| 55 |
|
| 56 |
- name: create test object in parent domain with domain_username creds - idempotent |
| 57 |
microsoft.ad.user: |
| 58 |
name: ParentUser1 |
| 59 |
path: '{{ parent_ou }}' |
| 60 |
state: present |
| 61 |
password: '{{ domain_password }}' |
| 62 |
update_password: when_changed |
| 63 |
domain_server: '{{ domain_realm }}' |
| 64 |
domain_username: '{{ domain_user_upn }}' |
| 65 |
domain_password: '{{ domain_password }}' |
| 66 |
register: user_with_creds1_again |
| 67 |
delegate_to: CHILD |
| 68 |
|
| 69 |
- name: assert create test object in parent domain with domain_username creds - idempotent |
| 70 |
assert: |
| 71 |
that: |
| 72 |
- not user_with_creds1_again is changed |
| 73 |
- user_with_creds1_again.distinguished_name == user_with_creds1.distinguished_name |
| 74 |
- user_with_creds1_again.object_guid == user_with_creds1.object_guid |
| 75 |
|
| 76 |
- name: create test object in parent domain with domain_credentials creds - check mode |
| 77 |
microsoft.ad.user: |
| 78 |
name: ParentUser2 |
| 79 |
path: '{{ parent_ou }}' |
| 80 |
state: present |
| 81 |
password: '{{ domain_password }}' |
| 82 |
update_password: when_changed |
| 83 |
domain_server: '{{ domain_realm }}' |
| 84 |
domain_credentials: |
| 85 |
- username: '{{ domain_user_upn }}' |
| 86 |
password: '{{ domain_password }}' |
| 87 |
register: user_with_creds2_check |
| 88 |
check_mode: true |
| 89 |
delegate_to: CHILD |
| 90 |
|
| 91 |
- name: get result of create test object in parent domain with domain_credentials creds - check mode |
| 92 |
microsoft.ad.object_info: |
| 93 |
identity: CN=ParentUser2,{{ parent_ou }} |
| 94 |
register: user_with_creds2_check_actual |
| 95 |
delegate_to: PARENT |
| 96 |
|
| 97 |
- name: assert create test object in parent domain with domain_credentials creds - check mode |
| 98 |
assert: |
| 99 |
that: |
| 100 |
- user_with_creds2_check is changed |
| 101 |
- user_with_creds2_check.distinguished_name == "CN=ParentUser2," ~ parent_ou |
| 102 |
- user_with_creds2_check_actual.objects == [] |
| 103 |
|
| 104 |
- name: create test object in parent domain with domain_credentials creds |
| 105 |
microsoft.ad.user: |
| 106 |
name: ParentUser2 |
| 107 |
path: '{{ parent_ou }}' |
| 108 |
state: present |
| 109 |
password: '{{ domain_password }}' |
| 110 |
update_password: when_changed |
| 111 |
domain_server: '{{ domain_realm }}' |
| 112 |
domain_credentials: |
| 113 |
- username: '{{ domain_user_upn }}' |
| 114 |
password: '{{ domain_password }}' |
| 115 |
register: user_with_creds2 |
| 116 |
delegate_to: CHILD |
| 117 |
|
| 118 |
- name: get result of create test object in parent domain with domain_credentials creds |
| 119 |
microsoft.ad.object_info: |
| 120 |
identity: CN=ParentUser2,{{ parent_ou }} |
| 121 |
register: user_with_creds2_actual |
| 122 |
delegate_to: PARENT |
| 123 |
|
| 124 |
- name: assert create test object in parent domain with domain_credentials creds |
| 125 |
assert: |
| 126 |
that: |
| 127 |
- user_with_creds2 is changed |
| 128 |
- user_with_creds2.distinguished_name == "CN=ParentUser2," ~ parent_ou |
| 129 |
- user_with_creds2_actual.objects | count == 1 |
| 130 |
- user_with_creds2_actual.objects[0].ObjectGUID == user_with_creds2.object_guid |
| 131 |
- user_with_creds2_actual.objects[0].DistinguishedName == user_with_creds2.distinguished_name |
| 132 |
|
| 133 |
- name: create test object in parent domain with domain_credentials creds - idempotent |
| 134 |
microsoft.ad.user: |
| 135 |
name: ParentUser2 |
| 136 |
path: '{{ parent_ou }}' |
| 137 |
state: present |
| 138 |
password: '{{ domain_password }}' |
| 139 |
update_password: when_changed |
| 140 |
domain_server: '{{ domain_realm }}' |
| 141 |
domain_credentials: |
| 142 |
- username: '{{ domain_user_upn }}' |
| 143 |
password: '{{ domain_password }}' |
| 144 |
register: user_with_creds2_again |
| 145 |
delegate_to: CHILD |
| 146 |
|
| 147 |
- name: assert create test object in parent domain with domain_credentials creds - idempotent |
| 148 |
assert: |
| 149 |
that: |
| 150 |
- not user_with_creds2_again is changed |
| 151 |
- user_with_creds2_again.distinguished_name == user_with_creds2.distinguished_name |
| 152 |
- user_with_creds2_again.object_guid == user_with_creds2.object_guid |
| 153 |
|
| 154 |
- name: edit user with domain_username creds - check mode |
| 155 |
microsoft.ad.user: |
| 156 |
name: ParentUser1 |
| 157 |
path: '{{ parent_ou }}' |
| 158 |
state: present |
| 159 |
password: '{{ domain_password }}' |
| 160 |
update_password: when_changed |
| 161 |
domain_server: '{{ domain_realm }}' |
| 162 |
domain_username: '{{ domain_user_upn }}' |
| 163 |
domain_password: '{{ domain_password }}' |
| 164 |
description: User Description |
| 165 |
spn: |
| 166 |
set: |
| 167 |
- HTTP/ParentUser1 |
| 168 |
attributes: |
| 169 |
set: |
| 170 |
comment: My comment |
| 171 |
register: set_with_creds1_check |
| 172 |
delegate_to: CHILD |
| 173 |
check_mode: true |
| 174 |
|
| 175 |
- name: get result of set user with domain_username creds - check mode |
| 176 |
microsoft.ad.object_info: |
| 177 |
identity: '{{ user_with_creds1.object_guid }}' |
| 178 |
properties: |
| 179 |
- comment |
| 180 |
- Description |
| 181 |
- servicePrincipalName |
| 182 |
register: set_with_creds1_check_actual |
| 183 |
delegate_to: PARENT |
| 184 |
|
| 185 |
- name: assert set user with domain_username creds - check mode |
| 186 |
assert: |
| 187 |
that: |
| 188 |
- set_with_creds1_check is changed |
| 189 |
- set_with_creds1_check.distinguished_name == user_with_creds1.distinguished_name |
| 190 |
- set_with_creds1_check.object_guid == user_with_creds1.object_guid |
| 191 |
- set_with_creds1_check_actual.objects[0].Description == None |
| 192 |
- set_with_creds1_check_actual.objects[0].DistinguishedName == user_with_creds1.distinguished_name |
| 193 |
- set_with_creds1_check_actual.objects[0].Name == 'ParentUser1' |
| 194 |
- set_with_creds1_check_actual.objects[0].ObjectGUID == user_with_creds1.object_guid |
| 195 |
- set_with_creds1_check_actual.objects[0].comment == None |
| 196 |
- set_with_creds1_check_actual.objects[0].servicePrincipalName == None |
| 197 |
|
| 198 |
- name: edit user with domain_username creds |
| 199 |
microsoft.ad.user: |
| 200 |
name: ParentUser1 |
| 201 |
path: '{{ parent_ou }}' |
| 202 |
state: present |
| 203 |
password: '{{ domain_password }}' |
| 204 |
update_password: when_changed |
| 205 |
domain_server: '{{ domain_realm }}' |
| 206 |
domain_username: '{{ domain_user_upn }}' |
| 207 |
domain_password: '{{ domain_password }}' |
| 208 |
description: User Description |
| 209 |
spn: |
| 210 |
set: |
| 211 |
- HTTP/ParentUser1 |
| 212 |
attributes: |
| 213 |
set: |
| 214 |
comment: My comment |
| 215 |
register: set_with_creds1 |
| 216 |
delegate_to: CHILD |
| 217 |
|
| 218 |
- name: get result of set user with domain_username creds |
| 219 |
microsoft.ad.object_info: |
| 220 |
identity: '{{ user_with_creds1.object_guid }}' |
| 221 |
properties: |
| 222 |
- comment |
| 223 |
- Description |
| 224 |
- servicePrincipalName |
| 225 |
register: set_with_creds1_actual |
| 226 |
delegate_to: PARENT |
| 227 |
|
| 228 |
- name: assert set user with domain_username creds |
| 229 |
assert: |
| 230 |
that: |
| 231 |
- set_with_creds1 is changed |
| 232 |
- set_with_creds1.distinguished_name == user_with_creds1.distinguished_name |
| 233 |
- set_with_creds1.object_guid == user_with_creds1.object_guid |
| 234 |
- set_with_creds1_actual.objects[0].Description == "User Description" |
| 235 |
- set_with_creds1_actual.objects[0].DistinguishedName == user_with_creds1.distinguished_name |
| 236 |
- set_with_creds1_actual.objects[0].Name == 'ParentUser1' |
| 237 |
- set_with_creds1_actual.objects[0].ObjectGUID == user_with_creds1.object_guid |
| 238 |
- set_with_creds1_actual.objects[0].comment == "My comment" |
| 239 |
- set_with_creds1_actual.objects[0].servicePrincipalName == ["HTTP/ParentUser1"] |
| 240 |
|
| 241 |
- name: edit user with domain_credentials creds - check mode |
| 242 |
microsoft.ad.user: |
| 243 |
name: ParentUser2 |
| 244 |
path: '{{ parent_ou }}' |
| 245 |
state: present |
| 246 |
password: '{{ domain_password }}' |
| 247 |
update_password: when_changed |
| 248 |
domain_server: '{{ domain_realm }}' |
| 249 |
domain_credentials: |
| 250 |
- username: '{{ domain_user_upn }}' |
| 251 |
password: '{{ domain_password }}' |
| 252 |
description: User Description |
| 253 |
spn: |
| 254 |
set: |
| 255 |
- HTTP/ParentUser2 |
| 256 |
attributes: |
| 257 |
set: |
| 258 |
comment: My comment |
| 259 |
register: set_with_creds2_check |
| 260 |
delegate_to: CHILD |
| 261 |
check_mode: true |
| 262 |
|
| 263 |
- name: get result of set user with domain_credentials creds - check mode |
| 264 |
microsoft.ad.object_info: |
| 265 |
identity: '{{ user_with_creds2.object_guid }}' |
| 266 |
properties: |
| 267 |
- comment |
| 268 |
- Description |
| 269 |
- servicePrincipalName |
| 270 |
register: set_with_creds2_check_actual |
| 271 |
delegate_to: PARENT |
| 272 |
|
| 273 |
- name: assert set user with domain_credentials creds - check mode |
| 274 |
assert: |
| 275 |
that: |
| 276 |
- set_with_creds2_check is changed |
| 277 |
- set_with_creds2_check.distinguished_name == user_with_creds2.distinguished_name |
| 278 |
- set_with_creds2_check.object_guid == user_with_creds2.object_guid |
| 279 |
- set_with_creds2_check_actual.objects[0].Description == None |
| 280 |
- set_with_creds2_check_actual.objects[0].DistinguishedName == user_with_creds2.distinguished_name |
| 281 |
- set_with_creds2_check_actual.objects[0].Name == 'ParentUser2' |
| 282 |
- set_with_creds2_check_actual.objects[0].ObjectGUID == user_with_creds2.object_guid |
| 283 |
- set_with_creds2_check_actual.objects[0].comment == None |
| 284 |
- set_with_creds2_check_actual.objects[0].servicePrincipalName == None |
| 285 |
|
| 286 |
- name: edit user with domain_credentials creds |
| 287 |
microsoft.ad.user: |
| 288 |
name: ParentUser2 |
| 289 |
path: '{{ parent_ou }}' |
| 290 |
state: present |
| 291 |
password: '{{ domain_password }}' |
| 292 |
update_password: when_changed |
| 293 |
domain_server: '{{ domain_realm }}' |
| 294 |
domain_credentials: |
| 295 |
- username: '{{ domain_user_upn }}' |
| 296 |
password: '{{ domain_password }}' |
| 297 |
description: User Description |
| 298 |
spn: |
| 299 |
set: |
| 300 |
- HTTP/ParentUser2 |
| 301 |
attributes: |
| 302 |
set: |
| 303 |
comment: My comment |
| 304 |
register: set_with_creds2 |
| 305 |
delegate_to: CHILD |
| 306 |
|
| 307 |
- name: get result of set user with domain_credentials creds |
| 308 |
microsoft.ad.object_info: |
| 309 |
identity: '{{ user_with_creds2.object_guid }}' |
| 310 |
properties: |
| 311 |
- comment |
| 312 |
- Description |
| 313 |
- servicePrincipalName |
| 314 |
register: set_with_creds2_actual |
| 315 |
delegate_to: PARENT |
| 316 |
|
| 317 |
- name: assert set user with domain_credentials creds |
| 318 |
assert: |
| 319 |
that: |
| 320 |
- set_with_creds2 is changed |
| 321 |
- set_with_creds2.distinguished_name == user_with_creds2.distinguished_name |
| 322 |
- set_with_creds2.object_guid == user_with_creds2.object_guid |
| 323 |
- set_with_creds2_actual.objects[0].Description == "User Description" |
| 324 |
- set_with_creds2_actual.objects[0].DistinguishedName == user_with_creds2.distinguished_name |
| 325 |
- set_with_creds2_actual.objects[0].Name == 'ParentUser2' |
| 326 |
- set_with_creds2_actual.objects[0].ObjectGUID == user_with_creds2.object_guid |
| 327 |
- set_with_creds2_actual.objects[0].comment == "My comment" |
| 328 |
- set_with_creds2_actual.objects[0].servicePrincipalName == ["HTTP/ParentUser2"] |
| 329 |
|
| 330 |
- name: set value with DN lookup and creds |
| 331 |
microsoft.ad.group: |
| 332 |
name: Group-CHILD |
| 333 |
path: '{{ child_ou }}' |
| 334 |
state: present |
| 335 |
members: |
| 336 |
add: |
| 337 |
- User-CHILD |
| 338 |
- name: User-PARENT |
| 339 |
server: '{{ domain_realm }}' |
| 340 |
domain_credentials: |
| 341 |
- name: '{{ domain_realm }}' |
| 342 |
username: '{{ domain_user_upn }}' |
| 343 |
password: '{{ domain_password }}' |
| 344 |
register: lookup_with_creds |
| 345 |
delegate_to: CHILD |
| 346 |
|
| 347 |
- name: get result of set value with DN lookup and creds |
| 348 |
microsoft.ad.object_info: |
| 349 |
identity: '{{ lookup_with_creds.object_guid }}' |
| 350 |
properties: |
| 351 |
- member |
| 352 |
register: lookup_with_creds_actual |
| 353 |
delegate_to: CHILD |
| 354 |
|
| 355 |
- name: assert set value with DN lookup and creds |
| 356 |
assert: |
| 357 |
that: |
| 358 |
- lookup_with_creds is changed |
| 359 |
- parent_user in lookup_with_creds_actual.objects[0].member |
| 360 |
- child_user in lookup_with_creds_actual.objects[0].member |
| 361 |
|
| 362 |
- name: set value with DN lookup and creds - idempotent |
| 363 |
microsoft.ad.group: |
| 364 |
name: Group-CHILD |
| 365 |
path: '{{ child_ou }}' |
| 366 |
state: present |
| 367 |
members: |
| 368 |
add: |
| 369 |
- User-CHILD |
| 370 |
- name: User-PARENT |
| 371 |
server: '{{ domain_realm }}' |
| 372 |
domain_credentials: |
| 373 |
- name: '{{ domain_realm }}' |
| 374 |
username: '{{ domain_user_upn }}' |
| 375 |
password: '{{ domain_password }}' |
| 376 |
register: lookup_with_creds_again |
| 377 |
delegate_to: CHILD |
| 378 |
|
| 379 |
- name: assert set value with DN lookup and creds - idempotent |
| 380 |
assert: |
| 381 |
that: |
| 382 |
- not lookup_with_creds_again is changed |
| 383 |
|
| 384 |
- name: create user group with DN lookup and creds - check mode |
| 385 |
microsoft.ad.user: |
| 386 |
name: ChildUser1 |
| 387 |
path: '{{ child_ou }}' |
| 388 |
state: present |
| 389 |
password: '{{ domain_password }}' |
| 390 |
update_password: when_changed |
| 391 |
domain_credentials: |
| 392 |
- name: '{{ domain_realm }}' |
| 393 |
username: '{{ domain_user_upn }}' |
| 394 |
password: '{{ domain_password }}' |
| 395 |
groups: |
| 396 |
add: |
| 397 |
- Group-CHILD |
| 398 |
- name: Group-PARENT |
| 399 |
server: '{{ domain_realm }}' |
| 400 |
register: new_user_with_group_check |
| 401 |
delegate_to: CHILD |
| 402 |
check_mode: true |
| 403 |
|
| 404 |
- name: get result of create user group with DN lookup and creds - check mode |
| 405 |
microsoft.ad.object_info: |
| 406 |
identity: '{{ new_user_with_group_check.distinguished_name }}' |
| 407 |
properties: |
| 408 |
- memberOf |
| 409 |
register: new_user_with_group_check_actual |
| 410 |
delegate_to: CHILD |
| 411 |
|
| 412 |
- name: assert set value with DN lookup and creds |
| 413 |
assert: |
| 414 |
that: |
| 415 |
- new_user_with_group_check is changed |
| 416 |
- new_user_with_group_check.distinguished_name == "CN=ChildUser1," ~ child_ou |
| 417 |
- new_user_with_group_check_actual.objects == [] |
| 418 |
|
| 419 |
- name: create user group with DN lookup and creds |
| 420 |
microsoft.ad.user: |
| 421 |
name: ChildUser1 |
| 422 |
path: '{{ child_ou }}' |
| 423 |
state: present |
| 424 |
password: '{{ domain_password }}' |
| 425 |
update_password: when_changed |
| 426 |
domain_credentials: |
| 427 |
- name: '{{ domain_realm }}' |
| 428 |
username: '{{ domain_user_upn }}' |
| 429 |
password: '{{ domain_password }}' |
| 430 |
groups: |
| 431 |
add: |
| 432 |
- Group-CHILD |
| 433 |
- name: Group-PARENT |
| 434 |
server: '{{ domain_realm }}' |
| 435 |
register: new_user_with_group |
| 436 |
delegate_to: CHILD |
| 437 |
|
| 438 |
- name: replicate group membership of parent group to child domain after adding group |
| 439 |
ansible.windows.win_command: >- |
| 440 |
repadmin.exe |
| 441 |
/replsingleobj |
| 442 |
{{ hostvars["CHILD"]["new_hostname"] }}.{{ hostvars["CHILD"]["child_domain_name"] }} |
| 443 |
parent.{{ domain_realm }} |
| 444 |
{{ parent_group }} |
| 445 |
delegate_to: CHILD |
| 446 |
|
| 447 |
- name: get result of create user group with DN lookup and creds |
| 448 |
microsoft.ad.object_info: |
| 449 |
identity: '{{ new_user_with_group.distinguished_name }}' |
| 450 |
properties: |
| 451 |
- memberOf |
| 452 |
register: new_user_with_group_actual |
| 453 |
delegate_to: CHILD |
| 454 |
|
| 455 |
- name: assert create user group with DN lookup and creds |
| 456 |
assert: |
| 457 |
that: |
| 458 |
- new_user_with_group is changed |
| 459 |
- new_user_with_group.distinguished_name == "CN=ChildUser1," ~ child_ou |
| 460 |
- new_user_with_group_actual.objects | count == 1 |
| 461 |
- new_user_with_group_actual.objects[0].DistinguishedName == new_user_with_group.distinguished_name |
| 462 |
- >- |
| 463 |
"CN=Group-CHILD," ~ child_ou in new_user_with_group_actual.objects[0].memberOf |
| 464 |
- >- |
| 465 |
"CN=Group-PARENT," ~ parent_ou in new_user_with_group_actual.objects[0].memberOf |
| 466 |
|
| 467 |
- name: create user group with DN lookup and creds - idempotent |
| 468 |
microsoft.ad.user: |
| 469 |
name: ChildUser1 |
| 470 |
path: '{{ child_ou }}' |
| 471 |
state: present |
| 472 |
password: '{{ domain_password }}' |
| 473 |
update_password: when_changed |
| 474 |
domain_credentials: |
| 475 |
- name: '{{ domain_realm }}' |
| 476 |
username: '{{ domain_user_upn }}' |
| 477 |
password: '{{ domain_password }}' |
| 478 |
groups: |
| 479 |
add: |
| 480 |
- Group-CHILD |
| 481 |
- name: Group-PARENT |
| 482 |
server: '{{ domain_realm }}' |
| 483 |
register: new_user_with_group_again |
| 484 |
delegate_to: CHILD |
| 485 |
|
| 486 |
- name: assert create user group with DN lookup and creds - idempotent |
| 487 |
assert: |
| 488 |
that: |
| 489 |
- not new_user_with_group_again is changed |
| 490 |
|
| 491 |
- name: remove user group with DN lookup and creds - check mode |
| 492 |
microsoft.ad.user: |
| 493 |
name: ChildUser1 |
| 494 |
path: '{{ child_ou }}' |
| 495 |
state: present |
| 496 |
password: '{{ domain_password }}' |
| 497 |
update_password: when_changed |
| 498 |
domain_credentials: |
| 499 |
- name: '{{ domain_realm }}' |
| 500 |
username: '{{ domain_user_upn }}' |
| 501 |
password: '{{ domain_password }}' |
| 502 |
groups: |
| 503 |
remove: |
| 504 |
- Group-CHILD |
| 505 |
- name: Group-PARENT |
| 506 |
server: '{{ domain_realm }}' |
| 507 |
register: remove_user_with_group_check |
| 508 |
delegate_to: CHILD |
| 509 |
check_mode: true |
| 510 |
|
| 511 |
- name: get result of remove user group with DN lookup and creds - check mode |
| 512 |
microsoft.ad.object_info: |
| 513 |
identity: '{{ remove_user_with_group_check.distinguished_name }}' |
| 514 |
properties: |
| 515 |
- memberOf |
| 516 |
register: remove_user_with_group_check_actual |
| 517 |
delegate_to: CHILD |
| 518 |
|
| 519 |
- name: assert remove user group with DN lookup and creds - check mode |
| 520 |
assert: |
| 521 |
that: |
| 522 |
- remove_user_with_group_check is changed |
| 523 |
- remove_user_with_group_check.distinguished_name == "CN=ChildUser1," ~ child_ou |
| 524 |
- >- |
| 525 |
"CN=Group-CHILD," ~ child_ou in remove_user_with_group_check_actual.objects[0].memberOf |
| 526 |
- >- |
| 527 |
"CN=Group-PARENT," ~ parent_ou in remove_user_with_group_check_actual.objects[0].memberOf |
| 528 |
|
| 529 |
- name: remove user group with DN lookup and creds |
| 530 |
microsoft.ad.user: |
| 531 |
name: ChildUser1 |
| 532 |
path: '{{ child_ou }}' |
| 533 |
state: present |
| 534 |
password: '{{ domain_password }}' |
| 535 |
update_password: when_changed |
| 536 |
domain_credentials: |
| 537 |
- name: '{{ domain_realm }}' |
| 538 |
username: '{{ domain_user_upn }}' |
| 539 |
password: '{{ domain_password }}' |
| 540 |
groups: |
| 541 |
remove: |
| 542 |
- Group-CHILD |
| 543 |
- name: Group-PARENT |
| 544 |
server: '{{ domain_realm }}' |
| 545 |
register: remove_user_with_group |
| 546 |
delegate_to: CHILD |
| 547 |
|
| 548 |
- name: replicate group membership of parent group to child domain after removing group |
| 549 |
ansible.windows.win_command: >- |
| 550 |
repadmin.exe |
| 551 |
/replsingleobj |
| 552 |
{{ hostvars["CHILD"]["new_hostname"] }}.{{ hostvars["CHILD"]["child_domain_name"] }} |
| 553 |
parent.{{ domain_realm }} |
| 554 |
{{ parent_group }} |
| 555 |
delegate_to: CHILD |
| 556 |
|
| 557 |
- name: get result of remove user group with DN lookup and creds |
| 558 |
microsoft.ad.object_info: |
| 559 |
identity: '{{ remove_user_with_group.distinguished_name }}' |
| 560 |
properties: |
| 561 |
- memberOf |
| 562 |
register: remove_user_with_group_actual |
| 563 |
delegate_to: CHILD |
| 564 |
|
| 565 |
- name: assert remove user group with DN lookup and creds |
| 566 |
assert: |
| 567 |
that: |
| 568 |
- remove_user_with_group is changed |
| 569 |
- remove_user_with_group.distinguished_name == "CN=ChildUser1," ~ child_ou |
| 570 |
- remove_user_with_group_actual.objects | count == 1 |
| 571 |
- remove_user_with_group_actual.objects[0].DistinguishedName == new_user_with_group.distinguished_name |
| 572 |
- remove_user_with_group_actual.objects[0].memberOf == None |
| 573 |
|
| 574 |
- name: remove user group with DN lookup and creds - idempotent |
| 575 |
microsoft.ad.user: |
| 576 |
name: ChildUser1 |
| 577 |
path: '{{ child_ou }}' |
| 578 |
state: present |
| 579 |
password: '{{ domain_password }}' |
| 580 |
update_password: when_changed |
| 581 |
domain_credentials: |
| 582 |
- name: '{{ domain_realm }}' |
| 583 |
username: '{{ domain_user_upn }}' |
| 584 |
password: '{{ domain_password }}' |
| 585 |
groups: |
| 586 |
remove: |
| 587 |
- Group-CHILD |
| 588 |
- name: Group-PARENT |
| 589 |
server: '{{ domain_realm }}' |
| 590 |
register: remove_user_with_group_again |
| 591 |
delegate_to: CHILD |
| 592 |
|
| 593 |
- name: assert remove user group with DN lookup and creds - idempotent |
| 594 |
assert: |
| 595 |
that: |
| 596 |
- not remove_user_with_group_again is changed |