| 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_iqn_pool: |
| 14 |
<<: *api_info |
| 15 |
name: "{{ item }}" |
| 16 |
state: absent |
| 17 |
loop: |
| 18 |
- test_iqn_pool |
| 19 |
- test_iqn_pool_2 |
| 20 |
|
| 21 |
- name: Create iqn pool - check-mode |
| 22 |
cisco.intersight.intersight_iqn_pool: |
| 23 |
<<: *api_info |
| 24 |
name: test_iqn_pool |
| 25 |
description: "Test iqn pool description" |
| 26 |
tags: |
| 27 |
- "Key": "Site" |
| 28 |
"Value": "Test" |
| 29 |
- "Key": "Site2" |
| 30 |
"Value": "Test3" |
| 31 |
prefix: "iqn.2025-08.com.cisco" |
| 32 |
iqn_suffix_blocks: |
| 33 |
- "suffix": "iqn" |
| 34 |
"iqn_from": 2 |
| 35 |
"size": 20 |
| 36 |
- "suffix": "iscsi" |
| 37 |
"iqn_from": 21 |
| 38 |
"size": 40 |
| 39 |
check_mode: true |
| 40 |
register: creation_res_check_mode |
| 41 |
|
| 42 |
- name: Verify iqn pool was not created - check-mode |
| 43 |
ansible.builtin.assert: |
| 44 |
that: |
| 45 |
- creation_res_check_mode is changed |
| 46 |
- creation_res_check_mode.api_response == {} |
| 47 |
|
| 48 |
- name: Create iqn pool |
| 49 |
cisco.intersight.intersight_iqn_pool: |
| 50 |
<<: *api_info |
| 51 |
name: test_iqn_pool |
| 52 |
description: "Test iqn pool description" |
| 53 |
tags: |
| 54 |
- "Key": "Site" |
| 55 |
"Value": "Test" |
| 56 |
- "Key": "Site2" |
| 57 |
"Value": "Test3" |
| 58 |
prefix: "iqn.2025-08.com.cisco" |
| 59 |
iqn_suffix_blocks: |
| 60 |
- "suffix": "iqn" |
| 61 |
"iqn_from": 1 |
| 62 |
"size": 20 |
| 63 |
- "suffix": "iscsi" |
| 64 |
"iqn_from": 51 |
| 65 |
"size": 40 |
| 66 |
register: creation_res |
| 67 |
|
| 68 |
- name: Fetch info after creation |
| 69 |
cisco.intersight.intersight_iqn_pool_info: |
| 70 |
<<: *api_info |
| 71 |
name: test_iqn_pool |
| 72 |
register: creation_info_res |
| 73 |
|
| 74 |
- name: Verify iqn pool creation by info |
| 75 |
ansible.builtin.assert: |
| 76 |
that: |
| 77 |
- creation_res.changed |
| 78 |
- creation_info_res.api_response[0].Name == 'test_iqn_pool' |
| 79 |
- creation_info_res.api_response[0].Prefix == 'iqn.2025-08.com.cisco' |
| 80 |
- creation_info_res.api_response[0].IqnSuffixBlocks[0]["Size"] == 20 |
| 81 |
- creation_info_res.api_response[0].IqnSuffixBlocks[0]["From"] == 1 |
| 82 |
- creation_info_res.api_response[0].IqnSuffixBlocks[1]["Size"] == 40 |
| 83 |
- creation_info_res.api_response[0].IqnSuffixBlocks[1]["From"] == 51 |
| 84 |
|
| 85 |
- name: Verify iqn pool creation response aligns with info response |
| 86 |
ansible.builtin.assert: |
| 87 |
that: |
| 88 |
- creation_res.api_response.Name == creation_info_res.api_response[0].Name |
| 89 |
- creation_res.api_response.Prefix == creation_info_res.api_response[0].Prefix |
| 90 |
- creation_res.api_response.IqnSuffixBlocks[0]["Size"] == creation_info_res.api_response[0].IqnSuffixBlocks[0]["Size"] |
| 91 |
- creation_res.api_response.IqnSuffixBlocks[0]["From"] == creation_info_res.api_response[0].IqnSuffixBlocks[0]["From"] |
| 92 |
|
| 93 |
- name: Create iqn pool (idempotency check) |
| 94 |
cisco.intersight.intersight_iqn_pool: |
| 95 |
<<: *api_info |
| 96 |
name: test_iqn_pool |
| 97 |
description: "Test iqn pool description" |
| 98 |
tags: |
| 99 |
- "Key": "Site" |
| 100 |
"Value": "Test" |
| 101 |
- "Key": "Site2" |
| 102 |
"Value": "Test3" |
| 103 |
prefix: "iqn.2025-08.com.cisco" |
| 104 |
iqn_suffix_blocks: |
| 105 |
- "suffix": "iqn" |
| 106 |
"iqn_from": 1 |
| 107 |
"size": 20 |
| 108 |
- "suffix": "iscsi" |
| 109 |
"iqn_from": 51 |
| 110 |
"size": 40 |
| 111 |
register: creation_res_ide |
| 112 |
|
| 113 |
- name: Verify iqn pool creation (idempotency check) |
| 114 |
ansible.builtin.assert: |
| 115 |
that: |
| 116 |
- not creation_res_ide.changed |
| 117 |
|
| 118 |
- name: Validate failure due to missing iqn_suffix_blocks |
| 119 |
cisco.intersight.intersight_iqn_pool: |
| 120 |
<<: *api_info |
| 121 |
name: test_iqn_pool_validate |
| 122 |
description: "Test iqn pool description" |
| 123 |
tags: |
| 124 |
- "Key": "Site" |
| 125 |
"Value": "Test" |
| 126 |
- "Key": "Site2" |
| 127 |
"Value": "Test3" |
| 128 |
state: present |
| 129 |
prefix: "iqn.2025-08.com.cisco" |
| 130 |
register: failure_res |
| 131 |
failed_when: |
| 132 |
- "'iqn_suffix_blocks parameter must be provided and contain at least one block' not in failure_res.msg" |
| 133 |
|
| 134 |
- name: Validate failure due to missing prefix |
| 135 |
cisco.intersight.intersight_iqn_pool: |
| 136 |
<<: *api_info |
| 137 |
name: test_iqn_pool_validate |
| 138 |
description: "Test iqn pool description" |
| 139 |
tags: |
| 140 |
- "Key": "Site" |
| 141 |
"Value": "Test" |
| 142 |
- "Key": "Site2" |
| 143 |
"Value": "Test3" |
| 144 |
state: present |
| 145 |
iqn_suffix_blocks: |
| 146 |
- "suffix": "iqn" |
| 147 |
"iqn_from": 1 |
| 148 |
"size": 20 |
| 149 |
- "suffix": "iscsi" |
| 150 |
"iqn_from": 51 |
| 151 |
"size": 40 |
| 152 |
register: failure_res |
| 153 |
failed_when: |
| 154 |
- "'prefix parameter must be provided' not in failure_res.msg" |
| 155 |
|
| 156 |
- name: Create another iqn pool |
| 157 |
cisco.intersight.intersight_iqn_pool: |
| 158 |
<<: *api_info |
| 159 |
name: test_iqn_pool_2 |
| 160 |
description: "Test iqn pool description" |
| 161 |
tags: |
| 162 |
- "Key": "Site" |
| 163 |
"Value": "Test" |
| 164 |
- "Key": "Site2" |
| 165 |
"Value": "Test3" |
| 166 |
prefix: "iqn.2025-08.net.cisco" |
| 167 |
iqn_suffix_blocks: |
| 168 |
- "suffix": "dev" |
| 169 |
"iqn_from": 101 |
| 170 |
"size": 80 |
| 171 |
register: creation_res_b |
| 172 |
|
| 173 |
- name: Fetch all iqn pools under default organization |
| 174 |
cisco.intersight.intersight_iqn_pool_info: |
| 175 |
<<: *api_info |
| 176 |
register: creation_info_res_b |
| 177 |
|
| 178 |
- name: Check that there are at least 2 iqn pools under this organization |
| 179 |
ansible.builtin.assert: |
| 180 |
that: |
| 181 |
- creation_info_res_b.api_response | length > 1 |
| 182 |
|
| 183 |
always: |
| 184 |
- name: Remove iqn pools |
| 185 |
cisco.intersight.intersight_iqn_pool: |
| 186 |
<<: *api_info |
| 187 |
name: "{{ item }}" |
| 188 |
state: absent |
| 189 |
loop: |
| 190 |
- test_iqn_pool |
| 191 |
- test_iqn_pool_2 |