| 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_macsec_policy: |
| 14 |
<<: *api_info |
| 15 |
name: "{{ item }}" |
| 16 |
state: absent |
| 17 |
loop: |
| 18 |
- test_macsec_policy_minimal |
| 19 |
- test_macsec_policy_fallback |
| 20 |
- test_macsec_policy_custom |
| 21 |
|
| 22 |
- name: Create MACsec Policy with minimal parameters - check-mode |
| 23 |
cisco.intersight.intersight_macsec_policy: |
| 24 |
<<: *api_info |
| 25 |
name: test_macsec_policy_minimal |
| 26 |
description: "Test MACsec Policy - Minimal Config" |
| 27 |
primary_keychain_name: "primary-keychain-minimal" |
| 28 |
primary_keys: |
| 29 |
- id: "1234" |
| 30 |
cryptographic_algorithm: "aes-256-cmac" |
| 31 |
secret: "Ja1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9bd2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c122222222222222222222222222222222222222222222" |
| 32 |
key_lifetime_always_active: true |
| 33 |
tags: |
| 34 |
- Key: Environment |
| 35 |
Value: Test |
| 36 |
check_mode: true |
| 37 |
register: minimal_creation_check_mode |
| 38 |
|
| 39 |
- name: Verify MACsec Policy was not created - check-mode |
| 40 |
ansible.builtin.assert: |
| 41 |
that: |
| 42 |
- minimal_creation_check_mode is changed |
| 43 |
- minimal_creation_check_mode.api_response == {} |
| 44 |
|
| 45 |
- name: Create MACsec Policy with minimal parameters |
| 46 |
cisco.intersight.intersight_macsec_policy: |
| 47 |
<<: *api_info |
| 48 |
name: test_macsec_policy_minimal |
| 49 |
description: "Test MACsec Policy - Minimal Config" |
| 50 |
primary_keychain_name: "primary-keychain-minimal" |
| 51 |
primary_keys: |
| 52 |
- id: "1234" |
| 53 |
cryptographic_algorithm: "aes-256-cmac" |
| 54 |
secret: "Ja1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9bd2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c122222222222222222222222222222222222222222222" |
| 55 |
key_lifetime_always_active: true |
| 56 |
tags: |
| 57 |
- Key: Environment |
| 58 |
Value: Test |
| 59 |
register: minimal_creation |
| 60 |
|
| 61 |
- name: Fetch info after minimal MACsec Policy creation |
| 62 |
cisco.intersight.intersight_macsec_policy_info: |
| 63 |
<<: *api_info |
| 64 |
name: test_macsec_policy_minimal |
| 65 |
register: minimal_info |
| 66 |
|
| 67 |
- name: Verify minimal MACsec Policy creation |
| 68 |
ansible.builtin.assert: |
| 69 |
that: |
| 70 |
- minimal_creation.changed |
| 71 |
- minimal_info.api_response[0].Name == 'test_macsec_policy_minimal' |
| 72 |
- minimal_info.api_response[0].CipherSuite == 'GCM-AES-XPN-256' |
| 73 |
- minimal_info.api_response[0].SecurityPolicy == 'Should-secure' |
| 74 |
- minimal_info.api_response[0].KeyServerPriority == 16 |
| 75 |
- minimal_info.api_response[0].PrimaryKeyChain.Name == 'primary-keychain-minimal' |
| 76 |
|
| 77 |
- name: Create MACsec Policy with minimal parameters (idempotency check) |
| 78 |
cisco.intersight.intersight_macsec_policy: |
| 79 |
<<: *api_info |
| 80 |
name: test_macsec_policy_minimal |
| 81 |
description: "Test MACsec Policy - Minimal Config" |
| 82 |
primary_keychain_name: "primary-keychain-minimal" |
| 83 |
primary_keys: |
| 84 |
- id: "1234" |
| 85 |
cryptographic_algorithm: "aes-256-cmac" |
| 86 |
secret: "Ja1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9bd2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c122222222222222222222222222222222222222222222" |
| 87 |
key_lifetime_always_active: true |
| 88 |
tags: |
| 89 |
- Key: Environment |
| 90 |
Value: Test |
| 91 |
register: minimal_creation_ide |
| 92 |
|
| 93 |
- name: Verify minimal MACsec Policy creation (idempotency check) |
| 94 |
ansible.builtin.assert: |
| 95 |
that: |
| 96 |
- not minimal_creation_ide.changed |
| 97 |
|
| 98 |
- name: Create MACsec Policy with Fallback Keychain |
| 99 |
cisco.intersight.intersight_macsec_policy: |
| 100 |
<<: *api_info |
| 101 |
name: test_macsec_policy_fallback |
| 102 |
description: "Test MACsec Policy - With Fallback" |
| 103 |
cipher_suite: "gcm-aes-256" |
| 104 |
security_policy: "must-secure" |
| 105 |
key_server_priority: 32 |
| 106 |
sak_expiry_time: 3600 |
| 107 |
primary_keychain_name: "primary-keychain-fallback" |
| 108 |
primary_keys: |
| 109 |
- id: "ABCD" |
| 110 |
cryptographic_algorithm: "aes-256-cmac" |
| 111 |
secret: "Ja1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9bd2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c122222222222222222222222222222222222222222222" |
| 112 |
key_lifetime_always_active: true |
| 113 |
configure_fallback_keychain: true |
| 114 |
fallback_keychain_name: "fallback-keychain" |
| 115 |
fallback_keys: |
| 116 |
- id: "EF12" |
| 117 |
cryptographic_algorithm: "aes-128-cmac" |
| 118 |
secret: "Ja1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b" |
| 119 |
key_lifetime_always_active: true |
| 120 |
tags: |
| 121 |
- Key: Environment |
| 122 |
Value: Test |
| 123 |
register: fallback_creation |
| 124 |
|
| 125 |
- name: Fetch info after MACsec Policy with fallback creation |
| 126 |
cisco.intersight.intersight_macsec_policy_info: |
| 127 |
<<: *api_info |
| 128 |
name: test_macsec_policy_fallback |
| 129 |
register: fallback_info |
| 130 |
|
| 131 |
- name: Verify MACsec Policy with fallback creation |
| 132 |
ansible.builtin.assert: |
| 133 |
that: |
| 134 |
- fallback_creation.changed |
| 135 |
- fallback_info.api_response[0].Name == 'test_macsec_policy_fallback' |
| 136 |
- fallback_info.api_response[0].CipherSuite == 'GCM-AES-256' |
| 137 |
- fallback_info.api_response[0].SecurityPolicy == 'Must-secure' |
| 138 |
- fallback_info.api_response[0].KeyServerPriority == 32 |
| 139 |
- fallback_info.api_response[0].SakExpiryTime == 3600 |
| 140 |
- fallback_info.api_response[0].PrimaryKeyChain.Name == 'primary-keychain-fallback' |
| 141 |
- fallback_info.api_response[0].FallbackKeyChain.Name == 'fallback-keychain' |
| 142 |
|
| 143 |
- name: Create MACsec Policy with Custom Settings |
| 144 |
cisco.intersight.intersight_macsec_policy: |
| 145 |
<<: *api_info |
| 146 |
name: test_macsec_policy_custom |
| 147 |
description: "Test MACsec Policy - Custom Settings" |
| 148 |
cipher_suite: "gcm-aes-xpn-128" |
| 149 |
confidentiality_offset: "conf-offset-30" |
| 150 |
security_policy: "must-secure" |
| 151 |
key_server_priority: 64 |
| 152 |
sak_expiry_time: 7200 |
| 153 |
replay_window_size: 200000000 |
| 154 |
include_icv_indicator: true |
| 155 |
eapol_mac_address: "0180.C200.0004" |
| 156 |
eapol_ethertype: "0x88e5" |
| 157 |
primary_keychain_name: "custom-keychain" |
| 158 |
primary_keys: |
| 159 |
- id: "2468" |
| 160 |
cryptographic_algorithm: "aes-256-cmac" |
| 161 |
secret: "Ja1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9bd2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c122222222222222222222222222222222222222222222" |
| 162 |
key_lifetime_always_active: true |
| 163 |
register: custom_creation |
| 164 |
|
| 165 |
- name: Fetch info after custom MACsec Policy creation |
| 166 |
cisco.intersight.intersight_macsec_policy_info: |
| 167 |
<<: *api_info |
| 168 |
name: test_macsec_policy_custom |
| 169 |
register: custom_info |
| 170 |
|
| 171 |
- name: Verify custom MACsec Policy creation |
| 172 |
ansible.builtin.assert: |
| 173 |
that: |
| 174 |
- custom_creation.changed |
| 175 |
- custom_info.api_response[0].Name == 'test_macsec_policy_custom' |
| 176 |
- custom_info.api_response[0].CipherSuite == 'GCM-AES-XPN-128' |
| 177 |
- custom_info.api_response[0].ConfidentialityOffset == 'CONF-OFFSET-30' |
| 178 |
- custom_info.api_response[0].SecurityPolicy == 'Must-secure' |
| 179 |
- custom_info.api_response[0].KeyServerPriority == 64 |
| 180 |
- custom_info.api_response[0].SakExpiryTime == 7200 |
| 181 |
- custom_info.api_response[0].ReplayWindowSize == 200000000 |
| 182 |
- custom_info.api_response[0].IncludeIcvIndicator == true |
| 183 |
- custom_info.api_response[0].MacSecEaPol.EaPolMacAddress == '0180.C200.0004' |
| 184 |
- custom_info.api_response[0].MacSecEaPol.EaPolEthertype == '0x88e5' |
| 185 |
|
| 186 |
- name: Update existing MACsec Policy |
| 187 |
cisco.intersight.intersight_macsec_policy: |
| 188 |
<<: *api_info |
| 189 |
name: test_macsec_policy_minimal |
| 190 |
description: "Updated MACsec Policy Description" |
| 191 |
primary_keychain_name: "primary-keychain-minimal" |
| 192 |
primary_keys: |
| 193 |
- id: "1234" |
| 194 |
cryptographic_algorithm: "aes-256-cmac" |
| 195 |
secret: "Ja1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9bd2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c122222222222222222222222222222222222222222222" |
| 196 |
key_lifetime_always_active: true |
| 197 |
tags: |
| 198 |
- Key: Environment |
| 199 |
Value: Updated |
| 200 |
register: minimal_update |
| 201 |
|
| 202 |
- name: Fetch info after policy update |
| 203 |
cisco.intersight.intersight_macsec_policy_info: |
| 204 |
<<: *api_info |
| 205 |
name: test_macsec_policy_minimal |
| 206 |
register: minimal_update_info |
| 207 |
|
| 208 |
- name: Verify policy update |
| 209 |
ansible.builtin.assert: |
| 210 |
that: |
| 211 |
- minimal_update.changed |
| 212 |
- minimal_update_info.api_response[0].Description == 'Updated MACsec Policy Description' |
| 213 |
|
| 214 |
- name: Fetch all MACsec Policies under selected organization |
| 215 |
cisco.intersight.intersight_macsec_policy_info: |
| 216 |
<<: *api_info |
| 217 |
register: all_policies_info |
| 218 |
|
| 219 |
- name: Check that there are MACsec Policies under this organization |
| 220 |
ansible.builtin.assert: |
| 221 |
that: |
| 222 |
- all_policies_info.api_response | length >= 3 |
| 223 |
|
| 224 |
- name: Test validation - Missing primary keychain name (should fail) |
| 225 |
cisco.intersight.intersight_macsec_policy: |
| 226 |
<<: *api_info |
| 227 |
name: test_validation_fail |
| 228 |
register: validation_fail_1 |
| 229 |
failed_when: |
| 230 |
- "'primary_keychain_name is required' not in validation_fail_1.msg" |
| 231 |
- not validation_fail_1.failed |
| 232 |
|
| 233 |
- name: Test validation - Invalid key_server_priority (should fail) |
| 234 |
cisco.intersight.intersight_macsec_policy: |
| 235 |
<<: *api_info |
| 236 |
name: test_validation_fail |
| 237 |
primary_keychain_name: "test-keychain" |
| 238 |
key_server_priority: 300 |
| 239 |
register: validation_fail_2 |
| 240 |
failed_when: |
| 241 |
- "'key_server_priority must be between 0 and 255' not in validation_fail_2.msg" |
| 242 |
- not validation_fail_2.failed |
| 243 |
|
| 244 |
- name: Test validation - Invalid sak_expiry_time (should fail) |
| 245 |
cisco.intersight.intersight_macsec_policy: |
| 246 |
<<: *api_info |
| 247 |
name: test_validation_fail |
| 248 |
primary_keychain_name: "test-keychain" |
| 249 |
sak_expiry_time: 50 |
| 250 |
register: validation_fail_3 |
| 251 |
failed_when: |
| 252 |
- "'sak_expiry_time must be between 60 and 2592000' not in validation_fail_3.msg" |
| 253 |
- not validation_fail_3.failed |
| 254 |
|
| 255 |
- name: Test validation - Invalid key ID (odd number of characters) (should fail) |
| 256 |
cisco.intersight.intersight_macsec_policy: |
| 257 |
<<: *api_info |
| 258 |
name: test_validation_fail |
| 259 |
primary_keychain_name: "test-keychain" |
| 260 |
primary_keys: |
| 261 |
- id: "123" |
| 262 |
secret: "Jtest" |
| 263 |
register: validation_fail_4 |
| 264 |
failed_when: |
| 265 |
- "'even number of characters' not in validation_fail_4.msg" |
| 266 |
- not validation_fail_4.failed |
| 267 |
|
| 268 |
- name: Test validation - Invalid octet string (should fail) |
| 269 |
cisco.intersight.intersight_macsec_policy: |
| 270 |
<<: *api_info |
| 271 |
name: test_validation_fail |
| 272 |
primary_keychain_name: "test-keychain" |
| 273 |
primary_keys: |
| 274 |
- id: "1234" |
| 275 |
secret: "Atest" |
| 276 |
register: validation_fail_5 |
| 277 |
failed_when: |
| 278 |
- "'must start with the character' not in validation_fail_5.msg" |
| 279 |
- not validation_fail_5.failed |
| 280 |
|
| 281 |
- name: Test validation - Missing fallback keychain name (should fail) |
| 282 |
cisco.intersight.intersight_macsec_policy: |
| 283 |
<<: *api_info |
| 284 |
name: test_validation_fail |
| 285 |
primary_keychain_name: "test-keychain" |
| 286 |
configure_fallback_keychain: true |
| 287 |
register: validation_fail_6 |
| 288 |
failed_when: |
| 289 |
- "'fallback_keychain_name is required' not in validation_fail_6.msg" |
| 290 |
- not validation_fail_6.failed |
| 291 |
|
| 292 |
always: |
| 293 |
- name: Remove all test MACsec Policies |
| 294 |
cisco.intersight.intersight_macsec_policy: |
| 295 |
<<: *api_info |
| 296 |
name: "{{ item }}" |
| 297 |
state: absent |
| 298 |
loop: |
| 299 |
- test_macsec_policy_minimal |
| 300 |
- test_macsec_policy_fallback |
| 301 |
- test_macsec_policy_custom |