| 1 |
--- |
| 2 |
- block: |
| 3 |
- name: Define anchor for Intersight API login info |
| 4 |
ansible.builtin.set_fact: |
| 5 |
api_info: &api_info |
| 6 |
api_private_key: "{{ api_private_key }}" |
| 7 |
api_key_id: "{{ api_key_id }}" |
| 8 |
api_uri: "{{ api_uri | default(omit) }}" |
| 9 |
validate_certs: "{{ validate_certs | default(omit) }}" |
| 10 |
organization: "{{ organization }}" |
| 11 |
|
| 12 |
- name: Make sure Env is clean |
| 13 |
cisco.intersight.intersight_ldap_policy: |
| 14 |
<<: *api_info |
| 15 |
name: "{{ item }}" |
| 16 |
state: absent |
| 17 |
loop: |
| 18 |
- test_ldap_policy_minimal |
| 19 |
- test_ldap_policy_dns |
| 20 |
- test_ldap_policy_providers |
| 21 |
- test_ldap_policy_configured_creds |
| 22 |
- test_ldap_policy_complex |
| 23 |
|
| 24 |
- name: Create LDAP policy with minimal parameters - check-mode |
| 25 |
cisco.intersight.intersight_ldap_policy: |
| 26 |
<<: *api_info |
| 27 |
name: test_ldap_policy_minimal |
| 28 |
description: "Test LDAP policy minimal" |
| 29 |
enable_ldap: true |
| 30 |
base_dn: "dc=test,dc=com" |
| 31 |
domain: "test.com" |
| 32 |
filter: "sAMAccountName" |
| 33 |
group_attribute: "memberOf" |
| 34 |
attribute: "CiscoAvPair" |
| 35 |
enable_dns: false |
| 36 |
ldap_providers: |
| 37 |
- server: "10.10.10.10" |
| 38 |
port: 389 |
| 39 |
vendor: "openldap" |
| 40 |
check_mode: true |
| 41 |
register: creation_res_check_mode |
| 42 |
|
| 43 |
- name: Verify LDAP policy was not created - check-mode |
| 44 |
ansible.builtin.assert: |
| 45 |
that: |
| 46 |
- creation_res_check_mode is changed |
| 47 |
- creation_res_check_mode.api_response == {} |
| 48 |
|
| 49 |
- name: Create LDAP policy with minimal parameters |
| 50 |
cisco.intersight.intersight_ldap_policy: |
| 51 |
<<: *api_info |
| 52 |
name: test_ldap_policy_minimal |
| 53 |
description: "Test LDAP policy minimal" |
| 54 |
enable_ldap: true |
| 55 |
base_dn: "dc=test,dc=com" |
| 56 |
domain: "test.com" |
| 57 |
filter: "sAMAccountName" |
| 58 |
group_attribute: "memberOf" |
| 59 |
attribute: "CiscoAvPair" |
| 60 |
enable_dns: false |
| 61 |
ldap_providers: |
| 62 |
- server: "10.10.10.10" |
| 63 |
port: 389 |
| 64 |
vendor: "openldap" |
| 65 |
register: creation_res |
| 66 |
|
| 67 |
- name: Fetch info after creation |
| 68 |
cisco.intersight.intersight_ldap_policy_info: |
| 69 |
<<: *api_info |
| 70 |
name: test_ldap_policy_minimal |
| 71 |
register: creation_info_res |
| 72 |
|
| 73 |
- name: Verify LDAP policy creation by info |
| 74 |
ansible.builtin.assert: |
| 75 |
that: |
| 76 |
- creation_res.changed |
| 77 |
- creation_info_res.api_response[0].Name == 'test_ldap_policy_minimal' |
| 78 |
- creation_info_res.api_response[0].Enabled == true |
| 79 |
- creation_info_res.api_response[0].BaseProperties.BaseDn == 'dc=test,dc=com' |
| 80 |
- creation_info_res.api_response[0].BaseProperties.Domain == 'test.com' |
| 81 |
- creation_info_res.api_response[0].BaseProperties.Filter == 'sAMAccountName' |
| 82 |
- creation_info_res.api_response[0].Groups is defined |
| 83 |
- creation_info_res.api_response[0].Providers is defined |
| 84 |
- creation_info_res.api_response[0].Providers | length == 1 |
| 85 |
- creation_info_res.api_response[0].Providers[0].Server == '10.10.10.10' |
| 86 |
|
| 87 |
- name: Create LDAP policy with minimal parameters (idempotency check) |
| 88 |
cisco.intersight.intersight_ldap_policy: |
| 89 |
<<: *api_info |
| 90 |
name: test_ldap_policy_minimal |
| 91 |
description: "Test LDAP policy minimal" |
| 92 |
enable_ldap: true |
| 93 |
base_dn: "dc=test,dc=com" |
| 94 |
domain: "test.com" |
| 95 |
filter: "sAMAccountName" |
| 96 |
group_attribute: "memberOf" |
| 97 |
attribute: "CiscoAvPair" |
| 98 |
enable_dns: false |
| 99 |
ldap_providers: |
| 100 |
- server: "10.10.10.10" |
| 101 |
port: 389 |
| 102 |
vendor: "openldap" |
| 103 |
register: idempotency_res |
| 104 |
|
| 105 |
- name: Verify idempotency |
| 106 |
ansible.builtin.assert: |
| 107 |
that: |
| 108 |
- idempotency_res is not changed |
| 109 |
|
| 110 |
- name: Update LDAP policy description and domain |
| 111 |
cisco.intersight.intersight_ldap_policy: |
| 112 |
<<: *api_info |
| 113 |
name: test_ldap_policy_minimal |
| 114 |
description: "Updated LDAP policy description" |
| 115 |
enable_ldap: true |
| 116 |
base_dn: "dc=test,dc=com" |
| 117 |
domain: "test.com2" |
| 118 |
filter: "sAMAccountName" |
| 119 |
group_attribute: "memberOf" |
| 120 |
attribute: "CiscoAvPair" |
| 121 |
enable_dns: false |
| 122 |
ldap_providers: |
| 123 |
- server: "10.10.10.10" |
| 124 |
port: 389 |
| 125 |
vendor: "openldap" |
| 126 |
register: update_res |
| 127 |
|
| 128 |
- name: Fetch info after update |
| 129 |
cisco.intersight.intersight_ldap_policy_info: |
| 130 |
<<: *api_info |
| 131 |
name: test_ldap_policy_minimal |
| 132 |
register: update_info_res |
| 133 |
|
| 134 |
- name: Verify update |
| 135 |
ansible.builtin.assert: |
| 136 |
that: |
| 137 |
- update_res is changed |
| 138 |
- update_info_res.api_response[0].Description == 'Updated LDAP policy description' |
| 139 |
- update_info_res.api_response[0].BaseProperties.Domain == 'test.com2' |
| 140 |
|
| 141 |
- name: Create LDAP policy with DNS enabled |
| 142 |
cisco.intersight.intersight_ldap_policy: |
| 143 |
<<: *api_info |
| 144 |
name: test_ldap_policy_dns |
| 145 |
description: "Test LDAP policy with DNS" |
| 146 |
tags: |
| 147 |
- Key: Environment |
| 148 |
Value: Test |
| 149 |
enable_ldap: true |
| 150 |
base_dn: "dc=example,dc=com" |
| 151 |
domain: "example.com" |
| 152 |
timeout: 30 |
| 153 |
enable_encryption: true |
| 154 |
bind_method: "logincredentials" |
| 155 |
filter: "sAMAccountName" |
| 156 |
group_attribute: "memberOf" |
| 157 |
attribute: "CiscoAvPair" |
| 158 |
group_authorization: true |
| 159 |
nested_group_search: true |
| 160 |
nested_group_search_depth: 64 |
| 161 |
enable_dns: true |
| 162 |
dns_source: "configured" |
| 163 |
search_domain: "example.com" |
| 164 |
search_forest: "example.com" |
| 165 |
user_search_precedence: "localuserdb" |
| 166 |
ldap_groups: |
| 167 |
- name: "admin-group" |
| 168 |
group_dn: "cn=admins,ou=groups,dc=example,dc=com" |
| 169 |
domain: "example.com" |
| 170 |
role: "admin" |
| 171 |
- name: "readonly-group" |
| 172 |
group_dn: "cn=readers,ou=groups,dc=example,dc=com" |
| 173 |
role: "readonly" |
| 174 |
register: dns_res |
| 175 |
|
| 176 |
- name: Fetch info after DNS-enabled LDAP policy creation |
| 177 |
cisco.intersight.intersight_ldap_policy_info: |
| 178 |
<<: *api_info |
| 179 |
name: test_ldap_policy_dns |
| 180 |
register: dns_info_res |
| 181 |
|
| 182 |
- name: Verify DNS-enabled LDAP policy creation by info |
| 183 |
ansible.builtin.assert: |
| 184 |
that: |
| 185 |
- dns_info_res.api_response[0].Name == 'test_ldap_policy_dns' |
| 186 |
- dns_info_res.api_response[0].EnableDns == true |
| 187 |
- dns_info_res.api_response[0].BaseProperties.EnableEncryption == true |
| 188 |
- dns_info_res.api_response[0].BaseProperties.Timeout == 30 |
| 189 |
- dns_info_res.api_response[0].BaseProperties.EnableGroupAuthorization == true |
| 190 |
- dns_info_res.api_response[0].BaseProperties.EnableNestedGroupSearch == true |
| 191 |
- dns_info_res.api_response[0].BaseProperties.NestedGroupSearchDepth == 64 |
| 192 |
- dns_info_res.api_response[0].Groups is defined |
| 193 |
- dns_info_res.api_response[0].Groups | length == 2 |
| 194 |
|
| 195 |
- name: Create LDAP policy with providers |
| 196 |
cisco.intersight.intersight_ldap_policy: |
| 197 |
<<: *api_info |
| 198 |
name: test_ldap_policy_providers |
| 199 |
description: "Test LDAP policy with providers" |
| 200 |
enable_ldap: true |
| 201 |
base_dn: "dc=company,dc=local" |
| 202 |
domain: "company.local" |
| 203 |
timeout: 0 |
| 204 |
enable_encryption: false |
| 205 |
bind_method: "anonymous" |
| 206 |
filter: "uid" |
| 207 |
group_attribute: "gidNumber" |
| 208 |
attribute: "description" |
| 209 |
group_authorization: false |
| 210 |
nested_group_search: false |
| 211 |
enable_dns: false |
| 212 |
user_search_precedence: "localuserdb" |
| 213 |
ldap_providers: |
| 214 |
- server: "10.10.10.10" |
| 215 |
port: 389 |
| 216 |
vendor: "openldap" |
| 217 |
- server: "10.10.10.11" |
| 218 |
port: 389 |
| 219 |
vendor: "openldap" |
| 220 |
ldap_groups: |
| 221 |
- name: "users-group" |
| 222 |
group_dn: "cn=users,ou=groups,dc=company,dc=local" |
| 223 |
role: "user" |
| 224 |
register: providers_res |
| 225 |
|
| 226 |
- name: Fetch info after provider-based LDAP policy creation |
| 227 |
cisco.intersight.intersight_ldap_policy_info: |
| 228 |
<<: *api_info |
| 229 |
name: test_ldap_policy_providers |
| 230 |
register: providers_info_res |
| 231 |
|
| 232 |
- name: Verify provider-based LDAP policy creation by info |
| 233 |
ansible.builtin.assert: |
| 234 |
that: |
| 235 |
- providers_res is changed |
| 236 |
- providers_info_res.api_response[0].Name == 'test_ldap_policy_providers' |
| 237 |
- providers_info_res.api_response[0].EnableDns == false |
| 238 |
- providers_info_res.api_response[0].BaseProperties.BindMethod == 'Anonymous' |
| 239 |
- providers_info_res.api_response[0].Providers | length == 2 |
| 240 |
- providers_info_res.api_response[0].Groups | length == 1 |
| 241 |
|
| 242 |
- name: Create LDAP policy with configured credentials |
| 243 |
cisco.intersight.intersight_ldap_policy: |
| 244 |
<<: *api_info |
| 245 |
name: test_ldap_policy_configured_creds |
| 246 |
description: "Test LDAP policy with configured credentials" |
| 247 |
enable_ldap: true |
| 248 |
base_dn: "dc=corp,dc=net" |
| 249 |
domain: "corp.net" |
| 250 |
timeout: 60 |
| 251 |
enable_encryption: true |
| 252 |
bind_method: "configuredcredentials" |
| 253 |
bind_dn: "cn=admin,dc=corp,dc=net" |
| 254 |
password: "TestPassword123" |
| 255 |
filter: "uid" |
| 256 |
group_attribute: "gidNumber" |
| 257 |
attribute: "description" |
| 258 |
group_authorization: true |
| 259 |
nested_group_search: true |
| 260 |
nested_group_search_depth: 128 |
| 261 |
enable_dns: false |
| 262 |
user_search_precedence: "ldapuserdb" |
| 263 |
ldap_providers: |
| 264 |
- server: "ldap.corp.net" |
| 265 |
port: 636 |
| 266 |
vendor: "msad" |
| 267 |
ldap_groups: |
| 268 |
- name: "administrators" |
| 269 |
group_dn: "cn=administrators,ou=groups,dc=corp,dc=net" |
| 270 |
domain: "corp.net" |
| 271 |
role: "admin" |
| 272 |
register: configured_creds_res |
| 273 |
|
| 274 |
- name: Fetch info after configured credentials LDAP policy creation |
| 275 |
cisco.intersight.intersight_ldap_policy_info: |
| 276 |
<<: *api_info |
| 277 |
name: test_ldap_policy_configured_creds |
| 278 |
register: configured_creds_info_res |
| 279 |
|
| 280 |
- name: Verify configured credentials LDAP policy creation |
| 281 |
ansible.builtin.assert: |
| 282 |
that: |
| 283 |
- configured_creds_res is changed |
| 284 |
- configured_creds_info_res.api_response[0].Name == 'test_ldap_policy_configured_creds' |
| 285 |
- configured_creds_info_res.api_response[0].BaseProperties.BindMethod == 'ConfiguredCredentials' |
| 286 |
- configured_creds_info_res.api_response[0].BaseProperties.BindDn == 'cn=admin,dc=corp,dc=net' |
| 287 |
- configured_creds_info_res.api_response[0].UserSearchPrecedence == 'LDAPUserDb' |
| 288 |
- configured_creds_info_res.api_response[0].Groups is defined |
| 289 |
- configured_creds_info_res.api_response[0].Groups | length == 1 |
| 290 |
- configured_creds_info_res.api_response[0].Providers is defined |
| 291 |
- configured_creds_info_res.api_response[0].Providers | length == 1 |
| 292 |
|
| 293 |
- name: Test LDAP policy with missing required parameter |
| 294 |
cisco.intersight.intersight_ldap_policy: |
| 295 |
<<: *api_info |
| 296 |
name: test_ldap_policy_invalid |
| 297 |
base_dn: "dc=test,dc=com" |
| 298 |
register: test_missing_required_result |
| 299 |
failed_when: |
| 300 |
- test_missing_required_result.failed == false |
| 301 |
- "'required' not in test_missing_required_result.msg" |
| 302 |
|
| 303 |
- name: Test LDAP policy with invalid timeout |
| 304 |
cisco.intersight.intersight_ldap_policy: |
| 305 |
<<: *api_info |
| 306 |
name: test_ldap_policy_invalid_timeout |
| 307 |
base_dn: "dc=test,dc=com" |
| 308 |
domain: "test.com" |
| 309 |
filter: "sAMAccountName" |
| 310 |
group_attribute: "memberOf" |
| 311 |
attribute: "CiscoAvPair" |
| 312 |
timeout: 200 |
| 313 |
register: test_invalid_timeout_result |
| 314 |
failed_when: |
| 315 |
- test_invalid_timeout_result.failed == false |
| 316 |
- "'timeout' not in test_invalid_timeout_result.msg" |
| 317 |
|
| 318 |
- name: Test LDAP policy with providers when DNS is enabled (should fail) |
| 319 |
cisco.intersight.intersight_ldap_policy: |
| 320 |
<<: *api_info |
| 321 |
name: test_ldap_policy_invalid_dns_providers |
| 322 |
base_dn: "dc=test,dc=com" |
| 323 |
domain: "test.com" |
| 324 |
filter: "sAMAccountName" |
| 325 |
group_attribute: "memberOf" |
| 326 |
attribute: "CiscoAvPair" |
| 327 |
enable_dns: true |
| 328 |
ldap_providers: |
| 329 |
- server: "10.10.10.10" |
| 330 |
port: 389 |
| 331 |
vendor: "openldap" |
| 332 |
register: test_dns_providers_conflict_result |
| 333 |
failed_when: |
| 334 |
- test_dns_providers_conflict_result.failed == false |
| 335 |
- "'cannot be specified when enable_dns is true' not in test_dns_providers_conflict_result.msg" |
| 336 |
|
| 337 |
- name: Test LDAP policy without providers when DNS is disabled (should fail) |
| 338 |
cisco.intersight.intersight_ldap_policy: |
| 339 |
<<: *api_info |
| 340 |
name: test_ldap_policy_no_providers |
| 341 |
base_dn: "dc=test,dc=com" |
| 342 |
domain: "test.com" |
| 343 |
filter: "sAMAccountName" |
| 344 |
group_attribute: "memberOf" |
| 345 |
attribute: "CiscoAvPair" |
| 346 |
enable_dns: false |
| 347 |
register: test_no_providers_result |
| 348 |
failed_when: |
| 349 |
- test_no_providers_result.failed == false |
| 350 |
- "'required when enable_dns is false' not in test_no_providers_result.msg" |
| 351 |
|
| 352 |
- name: Update LDAP policy - manage group states |
| 353 |
cisco.intersight.intersight_ldap_policy: |
| 354 |
<<: *api_info |
| 355 |
name: test_ldap_policy_dns |
| 356 |
description: "Updated with mixed group states" |
| 357 |
enable_ldap: true |
| 358 |
base_dn: "dc=example,dc=com" |
| 359 |
domain: "example.com" |
| 360 |
filter: "sAMAccountName" |
| 361 |
group_attribute: "memberOf" |
| 362 |
attribute: "CiscoAvPair" |
| 363 |
enable_dns: true |
| 364 |
ldap_groups: |
| 365 |
- name: "admin-group" |
| 366 |
group_dn: "cn=admins,ou=groups,dc=example,dc=com" |
| 367 |
role: "admin" |
| 368 |
state: present |
| 369 |
- name: "readonly-group" |
| 370 |
state: absent |
| 371 |
- name: "new-group" |
| 372 |
group_dn: "cn=new,ou=groups,dc=example,dc=com" |
| 373 |
role: "user" |
| 374 |
state: present |
| 375 |
register: mixed_groups_res |
| 376 |
|
| 377 |
- name: Fetch info after mixed group states update |
| 378 |
cisco.intersight.intersight_ldap_policy_info: |
| 379 |
<<: *api_info |
| 380 |
name: test_ldap_policy_dns |
| 381 |
register: mixed_groups_info_res |
| 382 |
|
| 383 |
- name: Verify mixed group states update |
| 384 |
ansible.builtin.assert: |
| 385 |
that: |
| 386 |
- mixed_groups_res is changed |
| 387 |
- mixed_groups_res.api_response.Groups | length == 2 |
| 388 |
- mixed_groups_info_res.api_response[0].Groups | length == 2 |
| 389 |
- mixed_groups_info_res.api_response[0].Groups[0].Name == 'admin-group' |
| 390 |
- mixed_groups_info_res.api_response[0].Groups[1].Name == 'new-group' |
| 391 |
|
| 392 |
- name: Fetch all LDAP policies |
| 393 |
cisco.intersight.intersight_ldap_policy_info: |
| 394 |
<<: *api_info |
| 395 |
register: all_policies_res |
| 396 |
|
| 397 |
- name: Verify multiple policies exist |
| 398 |
ansible.builtin.assert: |
| 399 |
that: |
| 400 |
- all_policies_res.api_response | length >= 4 |
| 401 |
|
| 402 |
- name: Delete LDAP policy |
| 403 |
cisco.intersight.intersight_ldap_policy: |
| 404 |
<<: *api_info |
| 405 |
name: test_ldap_policy_minimal |
| 406 |
state: absent |
| 407 |
register: deletion_res |
| 408 |
|
| 409 |
- name: Verify deletion |
| 410 |
ansible.builtin.assert: |
| 411 |
that: |
| 412 |
- deletion_res is changed |
| 413 |
|
| 414 |
- name: Delete LDAP policy (idempotency check) |
| 415 |
cisco.intersight.intersight_ldap_policy: |
| 416 |
<<: *api_info |
| 417 |
name: test_ldap_policy_minimal |
| 418 |
state: absent |
| 419 |
register: deletion_idempotency_res |
| 420 |
|
| 421 |
- name: Verify deletion idempotency |
| 422 |
ansible.builtin.assert: |
| 423 |
that: |
| 424 |
- deletion_idempotency_res is not changed |
| 425 |
|
| 426 |
always: |
| 427 |
- name: Clean up all test LDAP policies |
| 428 |
cisco.intersight.intersight_ldap_policy: |
| 429 |
<<: *api_info |
| 430 |
name: "{{ item }}" |
| 431 |
state: absent |
| 432 |
loop: |
| 433 |
- test_ldap_policy_minimal |
| 434 |
- test_ldap_policy_dns |
| 435 |
- test_ldap_policy_providers |
| 436 |
- test_ldap_policy_configured_creds |
| 437 |
- test_ldap_policy_complex |