| 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_vhba_template: |
| 14 |
<<: *api_info |
| 15 |
name: "{{ item }}" |
| 16 |
state: absent |
| 17 |
loop: |
| 18 |
- test_vhba_template |
| 19 |
- test_vhba_template_minimal |
| 20 |
- test_vhba_template_with_zones |
| 21 |
- test_vhba_template_pingroup |
| 22 |
|
| 23 |
# Create required policies for testing |
| 24 |
- name: Create WWPN pool for testing |
| 25 |
cisco.intersight.intersight_wwn_pool: |
| 26 |
<<: *api_info |
| 27 |
name: wwpn_pool_for_vhba_template |
| 28 |
pool_purpose: WWPN |
| 29 |
description: "Test WWPN pool for vHBA template" |
| 30 |
id_blocks: |
| 31 |
- wwn_from: "20:00:00:25:B5:00:00:00" |
| 32 |
size: 256 |
| 33 |
register: wwpn_pool_res |
| 34 |
|
| 35 |
- name: Create Fibre Channel Network policy for testing |
| 36 |
cisco.intersight.intersight_fibre_channel_network_policy: |
| 37 |
<<: *api_info |
| 38 |
name: fc_network_policy_for_vhba_template |
| 39 |
description: "Test FC Network policy for vHBA template" |
| 40 |
vsan_id: 100 |
| 41 |
register: fc_network_policy_res |
| 42 |
|
| 43 |
- name: Create Fibre Channel QoS policy for testing |
| 44 |
cisco.intersight.intersight_fibre_channel_qos_policy: |
| 45 |
<<: *api_info |
| 46 |
name: fc_qos_policy_for_vhba_template |
| 47 |
description: "Test FC QoS policy for vHBA template" |
| 48 |
burst: 1024 |
| 49 |
rate_limit: 0 |
| 50 |
cos: 3 |
| 51 |
max_data_field_size: 2112 |
| 52 |
register: fc_qos_policy_res |
| 53 |
|
| 54 |
- name: Create Fibre Channel Adapter policy for testing |
| 55 |
cisco.intersight.intersight_fibre_channel_adapter_policy: |
| 56 |
<<: *api_info |
| 57 |
name: fc_adapter_policy_for_vhba_template |
| 58 |
description: "Test FC Adapter policy for vHBA template" |
| 59 |
error_detection_timeout: 2000 |
| 60 |
resource_allocation_timeout: 10000 |
| 61 |
error_recovery_enabled: true |
| 62 |
register: fc_adapter_policy_res |
| 63 |
|
| 64 |
- name: Create Fibre Channel Zone policy for testing |
| 65 |
cisco.intersight.intersight_fibre_channel_zone_policy: |
| 66 |
<<: *api_info |
| 67 |
name: fc_zone_policy_for_vhba_template |
| 68 |
description: "Test FC Zone policy for vHBA template" |
| 69 |
fc_target_zoning_type: None |
| 70 |
register: fc_zone_policy_res |
| 71 |
|
| 72 |
- name: Create vHBA template - check-mode |
| 73 |
cisco.intersight.intersight_vhba_template: |
| 74 |
<<: *api_info |
| 75 |
name: test_vhba_template |
| 76 |
description: "Test vHBA template description" |
| 77 |
enable_override: false |
| 78 |
vhba_type: "fc-initiator" |
| 79 |
switch_id: "A" |
| 80 |
persistent_bindings: false |
| 81 |
wwpn_pool_name: "wwpn_pool_for_vhba_template" |
| 82 |
fibre_channel_network_policy_name: "fc_network_policy_for_vhba_template" |
| 83 |
fibre_channel_qos_policy_name: "fc_qos_policy_for_vhba_template" |
| 84 |
fibre_channel_adapter_policy_name: "fc_adapter_policy_for_vhba_template" |
| 85 |
tags: |
| 86 |
- Key: Site |
| 87 |
Value: Test |
| 88 |
- Key: Site2 |
| 89 |
Value: Test2 |
| 90 |
check_mode: true |
| 91 |
register: creation_res_check_mode |
| 92 |
|
| 93 |
- name: Verify vHBA template was not created - check-mode |
| 94 |
ansible.builtin.assert: |
| 95 |
that: |
| 96 |
- creation_res_check_mode is changed |
| 97 |
- creation_res_check_mode.api_response == {} |
| 98 |
|
| 99 |
- name: Create vHBA template |
| 100 |
cisco.intersight.intersight_vhba_template: |
| 101 |
<<: *api_info |
| 102 |
name: test_vhba_template |
| 103 |
description: "Test vHBA template description" |
| 104 |
enable_override: false |
| 105 |
vhba_type: "fc-initiator" |
| 106 |
switch_id: "A" |
| 107 |
persistent_bindings: false |
| 108 |
wwpn_pool_name: "wwpn_pool_for_vhba_template" |
| 109 |
fibre_channel_network_policy_name: "fc_network_policy_for_vhba_template" |
| 110 |
fibre_channel_qos_policy_name: "fc_qos_policy_for_vhba_template" |
| 111 |
fibre_channel_adapter_policy_name: "fc_adapter_policy_for_vhba_template" |
| 112 |
tags: |
| 113 |
- Key: Site |
| 114 |
Value: Test |
| 115 |
- Key: Site2 |
| 116 |
Value: Test2 |
| 117 |
register: creation_res |
| 118 |
|
| 119 |
- name: Fetch info after creation |
| 120 |
cisco.intersight.intersight_vhba_template_info: |
| 121 |
<<: *api_info |
| 122 |
name: test_vhba_template |
| 123 |
register: creation_info_res |
| 124 |
|
| 125 |
- name: Verify vHBA template creation via info module |
| 126 |
ansible.builtin.assert: |
| 127 |
that: |
| 128 |
- creation_res.changed |
| 129 |
- creation_info_res.api_response | length == 1 |
| 130 |
- creation_info_res.api_response[0].Name == 'test_vhba_template' |
| 131 |
- creation_info_res.api_response[0].Description == 'Test vHBA template description' |
| 132 |
- creation_info_res.api_response[0].EnableOverride == false |
| 133 |
- creation_info_res.api_response[0].Type == 'fc-initiator' |
| 134 |
- creation_info_res.api_response[0].SwitchId == 'A' |
| 135 |
- creation_info_res.api_response[0].PersistentBindings == false |
| 136 |
- creation_info_res.api_response[0].Tags | length == 2 |
| 137 |
- creation_info_res.api_response[0].ObjectType == 'vnic.VhbaTemplate' |
| 138 |
|
| 139 |
- name: Create same vHBA template again (idempotency) |
| 140 |
cisco.intersight.intersight_vhba_template: |
| 141 |
<<: *api_info |
| 142 |
name: test_vhba_template |
| 143 |
description: "Test vHBA template description" |
| 144 |
enable_override: false |
| 145 |
vhba_type: "fc-initiator" |
| 146 |
switch_id: "A" |
| 147 |
persistent_bindings: false |
| 148 |
wwpn_pool_name: "wwpn_pool_for_vhba_template" |
| 149 |
fibre_channel_network_policy_name: "fc_network_policy_for_vhba_template" |
| 150 |
fibre_channel_qos_policy_name: "fc_qos_policy_for_vhba_template" |
| 151 |
fibre_channel_adapter_policy_name: "fc_adapter_policy_for_vhba_template" |
| 152 |
tags: |
| 153 |
- Key: Site |
| 154 |
Value: Test |
| 155 |
- Key: Site2 |
| 156 |
Value: Test2 |
| 157 |
register: idempotency_res |
| 158 |
|
| 159 |
- name: Verify idempotency |
| 160 |
ansible.builtin.assert: |
| 161 |
that: |
| 162 |
- idempotency_res is not changed |
| 163 |
- idempotency_res.api_response.Name == 'test_vhba_template' |
| 164 |
|
| 165 |
- name: Update vHBA template |
| 166 |
cisco.intersight.intersight_vhba_template: |
| 167 |
<<: *api_info |
| 168 |
name: test_vhba_template |
| 169 |
description: "Updated vHBA template description" |
| 170 |
enable_override: true |
| 171 |
vhba_type: "fc-initiator" |
| 172 |
switch_id: "B" |
| 173 |
persistent_bindings: true |
| 174 |
wwpn_pool_name: "wwpn_pool_for_vhba_template" |
| 175 |
fibre_channel_network_policy_name: "fc_network_policy_for_vhba_template" |
| 176 |
fibre_channel_qos_policy_name: "fc_qos_policy_for_vhba_template" |
| 177 |
fibre_channel_adapter_policy_name: "fc_adapter_policy_for_vhba_template" |
| 178 |
tags: |
| 179 |
- Key: Site |
| 180 |
Value: Test |
| 181 |
- Key: Site2 |
| 182 |
Value: Test2 |
| 183 |
register: update_res |
| 184 |
|
| 185 |
- name: Fetch info after update |
| 186 |
cisco.intersight.intersight_vhba_template_info: |
| 187 |
<<: *api_info |
| 188 |
name: test_vhba_template |
| 189 |
register: update_info_res |
| 190 |
|
| 191 |
- name: Verify update via info module |
| 192 |
ansible.builtin.assert: |
| 193 |
that: |
| 194 |
- update_res.changed |
| 195 |
- update_info_res.api_response | length == 1 |
| 196 |
- update_info_res.api_response[0].Description == 'Updated vHBA template description' |
| 197 |
- update_info_res.api_response[0].EnableOverride == true |
| 198 |
- update_info_res.api_response[0].SwitchId == 'B' |
| 199 |
- update_info_res.api_response[0].PersistentBindings == true |
| 200 |
|
| 201 |
- name: Create vHBA template with minimal parameters |
| 202 |
cisco.intersight.intersight_vhba_template: |
| 203 |
<<: *api_info |
| 204 |
name: test_vhba_template_minimal |
| 205 |
vhba_type: "fc-initiator" |
| 206 |
wwpn_pool_name: "wwpn_pool_for_vhba_template" |
| 207 |
fibre_channel_network_policy_name: "fc_network_policy_for_vhba_template" |
| 208 |
fibre_channel_qos_policy_name: "fc_qos_policy_for_vhba_template" |
| 209 |
fibre_channel_adapter_policy_name: "fc_adapter_policy_for_vhba_template" |
| 210 |
register: minimal_res |
| 211 |
|
| 212 |
- name: Fetch info after minimal creation |
| 213 |
cisco.intersight.intersight_vhba_template_info: |
| 214 |
<<: *api_info |
| 215 |
name: test_vhba_template_minimal |
| 216 |
register: minimal_info_res |
| 217 |
|
| 218 |
- name: Verify minimal template creation via info module |
| 219 |
ansible.builtin.assert: |
| 220 |
that: |
| 221 |
- minimal_res.changed |
| 222 |
- minimal_info_res.api_response | length == 1 |
| 223 |
- minimal_info_res.api_response[0].Name == 'test_vhba_template_minimal' |
| 224 |
- minimal_info_res.api_response[0].EnableOverride == false |
| 225 |
- minimal_info_res.api_response[0].SwitchId == 'A' |
| 226 |
- minimal_info_res.api_response[0].PersistentBindings == false |
| 227 |
|
| 228 |
- name: Create vHBA template with FC Zone policies |
| 229 |
cisco.intersight.intersight_vhba_template: |
| 230 |
<<: *api_info |
| 231 |
name: test_vhba_template_with_zones |
| 232 |
description: "vHBA template with FC zone policies" |
| 233 |
vhba_type: "fc-initiator" |
| 234 |
wwpn_pool_name: "wwpn_pool_for_vhba_template" |
| 235 |
fibre_channel_network_policy_name: "fc_network_policy_for_vhba_template" |
| 236 |
fibre_channel_qos_policy_name: "fc_qos_policy_for_vhba_template" |
| 237 |
fibre_channel_adapter_policy_name: "fc_adapter_policy_for_vhba_template" |
| 238 |
fibre_channel_zone_policy_names: |
| 239 |
- "fc_zone_policy_for_vhba_template" |
| 240 |
register: with_zones_res |
| 241 |
|
| 242 |
- name: Fetch info after zones creation |
| 243 |
cisco.intersight.intersight_vhba_template_info: |
| 244 |
<<: *api_info |
| 245 |
name: test_vhba_template_with_zones |
| 246 |
register: with_zones_info_res |
| 247 |
|
| 248 |
- name: Verify template with zones via info module |
| 249 |
ansible.builtin.assert: |
| 250 |
that: |
| 251 |
- with_zones_res.changed |
| 252 |
- with_zones_info_res.api_response | length == 1 |
| 253 |
- with_zones_info_res.api_response[0].Name == 'test_vhba_template_with_zones' |
| 254 |
- with_zones_info_res.api_response[0].FcZonePolicies | length == 1 |
| 255 |
|
| 256 |
- name: Create vHBA template with pin group |
| 257 |
cisco.intersight.intersight_vhba_template: |
| 258 |
<<: *api_info |
| 259 |
name: test_vhba_template_pingroup |
| 260 |
description: "vHBA template with static pinning" |
| 261 |
vhba_type: "fc-nvme-initiator" |
| 262 |
persistent_bindings: true |
| 263 |
wwpn_pool_name: "wwpn_pool_for_vhba_template" |
| 264 |
fibre_channel_network_policy_name: "fc_network_policy_for_vhba_template" |
| 265 |
fibre_channel_qos_policy_name: "fc_qos_policy_for_vhba_template" |
| 266 |
fibre_channel_adapter_policy_name: "fc_adapter_policy_for_vhba_template" |
| 267 |
pin_group_name: "pingroup-a" |
| 268 |
register: with_pingroup_res |
| 269 |
|
| 270 |
- name: Fetch info after pingroup creation |
| 271 |
cisco.intersight.intersight_vhba_template_info: |
| 272 |
<<: *api_info |
| 273 |
name: test_vhba_template_pingroup |
| 274 |
register: with_pingroup_info_res |
| 275 |
|
| 276 |
- name: Verify template with pin group via info module |
| 277 |
ansible.builtin.assert: |
| 278 |
that: |
| 279 |
- with_pingroup_res.changed |
| 280 |
- with_pingroup_info_res.api_response | length == 1 |
| 281 |
- with_pingroup_info_res.api_response[0].Name == 'test_vhba_template_pingroup' |
| 282 |
- with_pingroup_info_res.api_response[0].Type == 'fc-nvme-initiator' |
| 283 |
- with_pingroup_info_res.api_response[0].PinGroupName == 'pingroup-a' |
| 284 |
|
| 285 |
- name: Test info module - get all templates |
| 286 |
cisco.intersight.intersight_vhba_template_info: |
| 287 |
<<: *api_info |
| 288 |
register: all_templates_res |
| 289 |
|
| 290 |
- name: Verify all templates returned |
| 291 |
ansible.builtin.assert: |
| 292 |
that: |
| 293 |
- all_templates_res.api_response | length >= 4 |
| 294 |
|
| 295 |
- name: Test info module - get specific template |
| 296 |
cisco.intersight.intersight_vhba_template_info: |
| 297 |
<<: *api_info |
| 298 |
name: test_vhba_template |
| 299 |
register: specific_template_res |
| 300 |
|
| 301 |
- name: Verify specific template info |
| 302 |
ansible.builtin.assert: |
| 303 |
that: |
| 304 |
- specific_template_res.api_response[0].Name == 'test_vhba_template' |
| 305 |
- specific_template_res.api_response[0].ObjectType == 'vnic.VhbaTemplate' |
| 306 |
|
| 307 |
- name: Test missing required parameter - vhba_type |
| 308 |
cisco.intersight.intersight_vhba_template: |
| 309 |
<<: *api_info |
| 310 |
name: test_invalid |
| 311 |
wwpn_pool_name: "wwpn_pool_for_vhba_template" |
| 312 |
fibre_channel_network_policy_name: "fc_network_policy_for_vhba_template" |
| 313 |
fibre_channel_qos_policy_name: "fc_qos_policy_for_vhba_template" |
| 314 |
fibre_channel_adapter_policy_name: "fc_adapter_policy_for_vhba_template" |
| 315 |
register: test_missing_vhba_type |
| 316 |
failed_when: |
| 317 |
- test_missing_vhba_type.failed == false |
| 318 |
- "'vhba_type' not in test_missing_vhba_type.msg" |
| 319 |
|
| 320 |
- name: Test missing WWPN pool |
| 321 |
cisco.intersight.intersight_vhba_template: |
| 322 |
<<: *api_info |
| 323 |
name: test_invalid |
| 324 |
vhba_type: "fc-initiator" |
| 325 |
fibre_channel_network_policy_name: "fc_network_policy_for_vhba_template" |
| 326 |
fibre_channel_qos_policy_name: "fc_qos_policy_for_vhba_template" |
| 327 |
fibre_channel_adapter_policy_name: "fc_adapter_policy_for_vhba_template" |
| 328 |
register: test_missing_wwpn_pool |
| 329 |
failed_when: |
| 330 |
- test_missing_wwpn_pool.failed == false |
| 331 |
- "'wwpn_pool_name' not in test_missing_wwpn_pool.msg" |
| 332 |
|
| 333 |
- name: Test nonexistent policy reference |
| 334 |
cisco.intersight.intersight_vhba_template: |
| 335 |
<<: *api_info |
| 336 |
name: test_invalid |
| 337 |
vhba_type: "fc-initiator" |
| 338 |
wwpn_pool_name: "nonexistent_wwpn_pool" |
| 339 |
fibre_channel_network_policy_name: "fc_network_policy_for_vhba_template" |
| 340 |
fibre_channel_qos_policy_name: "fc_qos_policy_for_vhba_template" |
| 341 |
fibre_channel_adapter_policy_name: "fc_adapter_policy_for_vhba_template" |
| 342 |
register: test_nonexistent_policy |
| 343 |
failed_when: |
| 344 |
- test_nonexistent_policy.failed == false |
| 345 |
- "'not found' not in test_nonexistent_policy.msg" |
| 346 |
|
| 347 |
always: |
| 348 |
- name: Clean up test resources |
| 349 |
cisco.intersight.intersight_vhba_template: |
| 350 |
<<: *api_info |
| 351 |
name: "{{ item }}" |
| 352 |
state: absent |
| 353 |
loop: |
| 354 |
- test_vhba_template |
| 355 |
- test_vhba_template_minimal |
| 356 |
- test_vhba_template_with_zones |
| 357 |
- test_vhba_template_pingroup |
| 358 |
ignore_errors: true |
| 359 |
|
| 360 |
- name: Clean up FC Zone Policy |
| 361 |
cisco.intersight.intersight_fibre_channel_zone_policy: |
| 362 |
<<: *api_info |
| 363 |
name: fc_zone_policy_for_vhba_template |
| 364 |
state: absent |
| 365 |
ignore_errors: true |
| 366 |
|
| 367 |
- name: Clean up FC Adapter Policy |
| 368 |
cisco.intersight.intersight_fibre_channel_adapter_policy: |
| 369 |
<<: *api_info |
| 370 |
name: fc_adapter_policy_for_vhba_template |
| 371 |
state: absent |
| 372 |
ignore_errors: true |
| 373 |
|
| 374 |
- name: Clean up FC QoS Policy |
| 375 |
cisco.intersight.intersight_fibre_channel_qos_policy: |
| 376 |
<<: *api_info |
| 377 |
name: fc_qos_policy_for_vhba_template |
| 378 |
state: absent |
| 379 |
ignore_errors: true |
| 380 |
|
| 381 |
- name: Clean up FC Network Policy |
| 382 |
cisco.intersight.intersight_fibre_channel_network_policy: |
| 383 |
<<: *api_info |
| 384 |
name: fc_network_policy_for_vhba_template |
| 385 |
state: absent |
| 386 |
ignore_errors: true |
| 387 |
|
| 388 |
- name: Clean up WWPN Pool |
| 389 |
cisco.intersight.intersight_wwn_pool: |
| 390 |
<<: *api_info |
| 391 |
name: wwpn_pool_for_vhba_template |
| 392 |
pool_purpose: WWPN |
| 393 |
state: absent |
| 394 |
ignore_errors: true |