| 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_ip_pool: |
| 14 |
<<: *api_info |
| 15 |
name: "{{ item }}" |
| 16 |
state: absent |
| 17 |
loop: |
| 18 |
- test_ip_pool |
| 19 |
- test_ip_pool_2 |
| 20 |
|
| 21 |
- name: Create ip pool with global config - check-mode |
| 22 |
cisco.intersight.intersight_ip_pool: |
| 23 |
<<: *api_info |
| 24 |
name: test_ip_pool |
| 25 |
description: IP Pool for lab use |
| 26 |
ipv4_config: |
| 27 |
netmask: "255.255.255.0" |
| 28 |
gateway: "172.17.116.1" |
| 29 |
primary_dns: "172.17.116.2" |
| 30 |
secondary_dns: "172.17.116.3" |
| 31 |
ipv4_blocks: |
| 32 |
- from: "172.17.116.32" |
| 33 |
size: 16 |
| 34 |
- from: "172.17.116.64" |
| 35 |
size: 16 |
| 36 |
ipv6_config: |
| 37 |
prefix: 64 |
| 38 |
gateway: "2001:db8::1" |
| 39 |
primary_dns: "2001:4860:4860::8888" |
| 40 |
secondary_dns: "2001:4860:4860::8844" |
| 41 |
ipv6_blocks: |
| 42 |
- from: "2001:db8::2" |
| 43 |
size: 64 |
| 44 |
- from: "2001:db8::42" |
| 45 |
size: 64 |
| 46 |
tags: |
| 47 |
- Key: Site |
| 48 |
Value: RCDN |
| 49 |
check_mode: true |
| 50 |
register: creation_res_check_mode |
| 51 |
|
| 52 |
- name: Verify ip pool was not created - check-mode |
| 53 |
ansible.builtin.assert: |
| 54 |
that: |
| 55 |
- creation_res_check_mode is changed |
| 56 |
- creation_res_check_mode.api_response == {} |
| 57 |
|
| 58 |
- name: Create ip pool with global config |
| 59 |
cisco.intersight.intersight_ip_pool: |
| 60 |
<<: *api_info |
| 61 |
name: test_ip_pool |
| 62 |
description: IP Pool for lab use |
| 63 |
ipv4_config: |
| 64 |
netmask: "255.255.255.0" |
| 65 |
gateway: "172.17.116.1" |
| 66 |
primary_dns: "172.17.116.2" |
| 67 |
secondary_dns: "172.17.116.3" |
| 68 |
ipv4_blocks: |
| 69 |
- from: "172.17.116.32" |
| 70 |
size: 16 |
| 71 |
- from: "172.17.116.64" |
| 72 |
size: 16 |
| 73 |
ipv6_config: |
| 74 |
prefix: 64 |
| 75 |
gateway: "2001:db8::1" |
| 76 |
primary_dns: "2001:4860:4860::8888" |
| 77 |
secondary_dns: "2001:4860:4860::8844" |
| 78 |
ipv6_blocks: |
| 79 |
- from: "2001:db8::2" |
| 80 |
size: 64 |
| 81 |
- from: "2001:db8::42" |
| 82 |
size: 64 |
| 83 |
tags: |
| 84 |
- Key: Site |
| 85 |
Value: RCDN |
| 86 |
register: creation_res |
| 87 |
|
| 88 |
- name: Fetch info for test_ip_pool after creation |
| 89 |
cisco.intersight.intersight_ip_pool_info: |
| 90 |
<<: *api_info |
| 91 |
name: test_ip_pool |
| 92 |
register: creation_info_res |
| 93 |
|
| 94 |
- name: Verify ip pool creation by info |
| 95 |
ansible.builtin.assert: |
| 96 |
that: |
| 97 |
- creation_res.changed |
| 98 |
- creation_info_res.api_response[0].Name == 'test_ip_pool' |
| 99 |
- creation_info_res.api_response[0].IpV4Blocks[0]["Size"] == 16 |
| 100 |
- creation_info_res.api_response[0].IpV4Blocks[0]["From"] == '172.17.116.32' |
| 101 |
- creation_info_res.api_response[0].IpV4Blocks[1]["Size"] == 16 |
| 102 |
- creation_info_res.api_response[0].IpV4Blocks[1]["From"] == '172.17.116.64' |
| 103 |
- creation_info_res.api_response[0].IpV6Blocks[0]["Size"] == 64 |
| 104 |
- creation_info_res.api_response[0].IpV6Blocks[0]["From"] == '2001:db8::2' |
| 105 |
- creation_info_res.api_response[0].IpV6Blocks[1]["Size"] == 64 |
| 106 |
- creation_info_res.api_response[0].IpV6Blocks[1]["From"] == '2001:db8::42' |
| 107 |
- creation_info_res.api_response[0].IpV4Config["Gateway"] == '172.17.116.1' |
| 108 |
- creation_info_res.api_response[0].IpV4Config["Netmask"] == '255.255.255.0' |
| 109 |
- creation_info_res.api_response[0].IpV4Config["PrimaryDns"] == '172.17.116.2' |
| 110 |
- creation_info_res.api_response[0].IpV6Config["Gateway"] == '2001:db8::1' |
| 111 |
- creation_info_res.api_response[0].IpV6Config["Prefix"] == 64 |
| 112 |
- creation_info_res.api_response[0].IpV6Config["PrimaryDns"] == '2001:4860:4860::8888' |
| 113 |
|
| 114 |
|
| 115 |
- name: Verify ip pool creation response aligns with info response |
| 116 |
ansible.builtin.assert: |
| 117 |
that: |
| 118 |
- creation_res.api_response.Name == creation_info_res.api_response[0].Name |
| 119 |
- creation_res.api_response.IpV4Blocks[0]["Size"] == creation_info_res.api_response[0].IpV4Blocks[0]["Size"] |
| 120 |
- creation_res.api_response.IpV4Blocks[0]["From"] == creation_info_res.api_response[0].IpV4Blocks[0]["From"] |
| 121 |
- creation_res.api_response.IpV6Blocks[0]["Size"] == creation_info_res.api_response[0].IpV6Blocks[0]["Size"] |
| 122 |
- creation_res.api_response.IpV6Blocks[0]["From"] == creation_info_res.api_response[0].IpV6Blocks[0]["From"] |
| 123 |
- creation_res.api_response.IpV4Config["Gateway"] == creation_info_res.api_response[0].IpV4Config["Gateway"] |
| 124 |
- creation_res.api_response.IpV6Config["Gateway"] == creation_info_res.api_response[0].IpV6Config["Gateway"] |
| 125 |
|
| 126 |
- name: Create ip pool (idempotency check) |
| 127 |
cisco.intersight.intersight_ip_pool: |
| 128 |
<<: *api_info |
| 129 |
name: test_ip_pool |
| 130 |
description: IP Pool for lab use |
| 131 |
ipv4_config: |
| 132 |
netmask: "255.255.255.0" |
| 133 |
gateway: "172.17.116.1" |
| 134 |
primary_dns: "172.17.116.2" |
| 135 |
secondary_dns: "172.17.116.3" |
| 136 |
ipv4_blocks: |
| 137 |
- from: "172.17.116.32" |
| 138 |
size: 16 |
| 139 |
- from: "172.17.116.64" |
| 140 |
size: 16 |
| 141 |
ipv6_config: |
| 142 |
prefix: 64 |
| 143 |
gateway: "2001:db8::1" |
| 144 |
primary_dns: "2001:4860:4860::8888" |
| 145 |
secondary_dns: "2001:4860:4860::8844" |
| 146 |
ipv6_blocks: |
| 147 |
- from: "2001:db8::2" |
| 148 |
size: 64 |
| 149 |
- from: "2001:db8::42" |
| 150 |
size: 64 |
| 151 |
tags: |
| 152 |
- Key: Site |
| 153 |
Value: RCDN |
| 154 |
register: creation_res_ide |
| 155 |
|
| 156 |
- name: Verify ip pool creation (idempotency check) |
| 157 |
ansible.builtin.assert: |
| 158 |
that: |
| 159 |
- not creation_res_ide.changed |
| 160 |
|
| 161 |
- name: Validate failure due to missing ipv4_blocks |
| 162 |
cisco.intersight.intersight_ip_pool: |
| 163 |
<<: *api_info |
| 164 |
name: test_ip_pool_validate |
| 165 |
description: "Test ip pool description" |
| 166 |
tags: [ |
| 167 |
{ |
| 168 |
"Key": "Site", "Value": "Test" |
| 169 |
}, |
| 170 |
{ |
| 171 |
"Key": "Site2", "Value": "Test3" |
| 172 |
} |
| 173 |
] |
| 174 |
state: present |
| 175 |
register: failure_res |
| 176 |
failed_when: |
| 177 |
- "'at least one of ipv4_blocks/ipv6_blocks parameters must be provided and contain at least one block when state is present' not in failure_res.msg" |
| 178 |
|
| 179 |
- name: Create ip pool with block level config |
| 180 |
cisco.intersight.intersight_ip_pool: |
| 181 |
<<: *api_info |
| 182 |
name: test_ip_pool_2 |
| 183 |
description: IP Pool for lab use 2 |
| 184 |
enable_block_level_subnet_config: true |
| 185 |
ipv4_blocks: |
| 186 |
- from: "172.17.116.32" |
| 187 |
size: 16 |
| 188 |
ipv4_config: |
| 189 |
netmask: "255.255.255.0" |
| 190 |
gateway: "172.17.116.1" |
| 191 |
primary_dns: "172.17.116.2" |
| 192 |
secondary_dns: "172.17.116.3" |
| 193 |
- from: "172.17.117.32" |
| 194 |
size: 16 |
| 195 |
ipv4_config: |
| 196 |
netmask: "255.255.255.0" |
| 197 |
gateway: "172.17.117.1" |
| 198 |
primary_dns: "172.17.117.2" |
| 199 |
secondary_dns: "172.17.117.3" |
| 200 |
ipv6_blocks: |
| 201 |
- from: "2001:db8::2" |
| 202 |
size: 64 |
| 203 |
ipv6_config: |
| 204 |
prefix: 64 |
| 205 |
gateway: "2001:db8::1" |
| 206 |
primary_dns: "2001:4860:4860::8888" |
| 207 |
secondary_dns: "2001:4860:4860::8844" |
| 208 |
- from: "fd12:3456:789a::1" |
| 209 |
size: 64 |
| 210 |
ipv6_config: |
| 211 |
prefix: 64 |
| 212 |
gateway: "fd12:3456:789a::1" |
| 213 |
primary_dns: "2606:4700:4700::1111" |
| 214 |
secondary_dns: "2606:4700:4700::1001" |
| 215 |
tags: |
| 216 |
- Key: Site |
| 217 |
Value: RCDN |
| 218 |
register: creation_res_b |
| 219 |
|
| 220 |
|
| 221 |
- name: Fetch info for test_ip_pool_2 after creation |
| 222 |
cisco.intersight.intersight_ip_pool_info: |
| 223 |
<<: *api_info |
| 224 |
name: test_ip_pool_2 |
| 225 |
register: creation_info_res_b |
| 226 |
|
| 227 |
- name: Verify ip pool 2 creation by info |
| 228 |
ansible.builtin.assert: |
| 229 |
that: |
| 230 |
- creation_res_b.changed |
| 231 |
- creation_info_res_b.api_response[0].Name == 'test_ip_pool_2' |
| 232 |
- creation_info_res_b.api_response[0].IpV4Blocks[0]["Size"] == 16 |
| 233 |
- creation_info_res_b.api_response[0].IpV4Blocks[0]["From"] == '172.17.116.32' |
| 234 |
- creation_info_res_b.api_response[0].IpV4Blocks[0]["IpV4Config"]["Gateway"] == '172.17.116.1' |
| 235 |
- creation_info_res_b.api_response[0].IpV4Blocks[1]["Size"] == 16 |
| 236 |
- creation_info_res_b.api_response[0].IpV4Blocks[1]["From"] == '172.17.117.32' |
| 237 |
- creation_info_res_b.api_response[0].IpV4Blocks[1]["IpV4Config"]["Gateway"] == '172.17.117.1' |
| 238 |
- creation_info_res_b.api_response[0].IpV6Blocks[0]["Size"] == 64 |
| 239 |
- creation_info_res_b.api_response[0].IpV6Blocks[0]["From"] == '2001:db8::2' |
| 240 |
- creation_info_res_b.api_response[0].IpV6Blocks[0]["IpV6Config"]["Gateway"] == '2001:db8::1' |
| 241 |
- creation_info_res_b.api_response[0].IpV6Blocks[1]["Size"] == 64 |
| 242 |
- creation_info_res_b.api_response[0].IpV6Blocks[1]["From"] == 'fd12:3456:789a::1' |
| 243 |
- creation_info_res_b.api_response[0].IpV6Blocks[1]["IpV6Config"]["Gateway"] == 'fd12:3456:789a::1' |
| 244 |
|
| 245 |
- name: Verify ip pool 2 creation response aligns with info response |
| 246 |
ansible.builtin.assert: |
| 247 |
that: |
| 248 |
- creation_res_b.api_response.Name == creation_info_res_b.api_response[0].Name |
| 249 |
- creation_res_b.api_response.IpV4Blocks[0]["Size"] == creation_info_res_b.api_response[0].IpV4Blocks[0]["Size"] |
| 250 |
- creation_res_b.api_response.IpV4Blocks[0]["From"] == creation_info_res_b.api_response[0].IpV4Blocks[0]["From"] |
| 251 |
- creation_res_b.api_response.IpV6Blocks[0]["Size"] == creation_info_res_b.api_response[0].IpV6Blocks[0]["Size"] |
| 252 |
- creation_res_b.api_response.IpV6Blocks[0]["From"] == creation_info_res_b.api_response[0].IpV6Blocks[0]["From"] |
| 253 |
- creation_res_b.api_response.IpV4Blocks[0]["IpV4Config"]["Gateway"] == creation_info_res_b.api_response[0].IpV4Blocks[0]["IpV4Config"]["Gateway"] |
| 254 |
- creation_res_b.api_response.IpV6Blocks[0]["IpV6Config"]["Gateway"] == creation_info_res_b.api_response[0].IpV6Blocks[0]["IpV6Config"]["Gateway"] |
| 255 |
|
| 256 |
- name: Fetch all ip pools under default organization |
| 257 |
cisco.intersight.intersight_ip_pool_info: |
| 258 |
<<: *api_info |
| 259 |
register: creation_info_res_all |
| 260 |
|
| 261 |
- name: Check that there are at least 2 ip pools under this organization |
| 262 |
ansible.builtin.assert: |
| 263 |
that: |
| 264 |
- creation_info_res_all.api_response | length > 1 |
| 265 |
|
| 266 |
always: |
| 267 |
- name: Remove ip pools |
| 268 |
cisco.intersight.intersight_ip_pool: |
| 269 |
<<: *api_info |
| 270 |
name: "{{ item }}" |
| 271 |
state: absent |
| 272 |
loop: |
| 273 |
- test_ip_pool |
| 274 |
- test_ip_pool_2 |