| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
- name: Test that we have an ACI APIC host, ACI username and ACI password |
| 7 |
ansible.builtin.fail: |
| 8 |
msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.' |
| 9 |
when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined |
| 10 |
|
| 11 |
|
| 12 |
- name: Set vars |
| 13 |
ansible.builtin.set_fact: |
| 14 |
aci_info: &aci_info |
| 15 |
host: "{{ aci_hostname }}" |
| 16 |
username: "{{ aci_username }}" |
| 17 |
password: "{{ aci_password }}" |
| 18 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 19 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 20 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 21 |
output_level: '{{ aci_output_level | default("info") }}' |
| 22 |
|
| 23 |
- name: Verify Cloud and Non-Cloud Sites in use. |
| 24 |
ansible.builtin.include_tasks: ../../../../../../integration/targets/aci_cloud_provider/tasks/main.yml |
| 25 |
|
| 26 |
- name: Execute tasks only for cloud sites |
| 27 |
when: query_cloud.current | length > 0 |
| 28 |
block: |
| 29 |
- name: Ensure tenant doesn't exist |
| 30 |
cisco.aci.aci_tenant: |
| 31 |
<<: *aci_info |
| 32 |
state: absent |
| 33 |
tenant: ansible_test |
| 34 |
register: tenant_absent |
| 35 |
|
| 36 |
- name: Ensure tenant exists for tests to kick off |
| 37 |
cisco.aci.aci_tenant: |
| 38 |
<<: *aci_info |
| 39 |
state: present |
| 40 |
tenant: ansible_test |
| 41 |
register: tenant_present |
| 42 |
|
| 43 |
- name: Ensure aci cloud context profile does not exists |
| 44 |
cisco.aci.aci_cloud_ctx_profile: |
| 45 |
<<: *aci_info |
| 46 |
tenant: ansible_test |
| 47 |
name: ctx_profile_1 |
| 48 |
state: absent |
| 49 |
register: rm_ctx_profile_1 |
| 50 |
|
| 51 |
- name: Create aci cloud context profile |
| 52 |
cisco.aci.aci_cloud_ctx_profile: |
| 53 |
<<: *aci_info |
| 54 |
tenant: ansible_test |
| 55 |
name: ctx_profile_1 |
| 56 |
vrf: ctx_profile_vrf_1 |
| 57 |
region: "{{ region_2 }}" |
| 58 |
primary_cidr: '10.11.0.0/16' |
| 59 |
cloud: "{{ cloud_type }}" |
| 60 |
state: present |
| 61 |
register: nm_add_aci_ctx_profile |
| 62 |
|
| 63 |
- name: Create non_primary CIDR (check_mode) |
| 64 |
cisco.aci.aci_cloud_cidr: |
| 65 |
<<: *aci_info |
| 66 |
tenant: ansible_test |
| 67 |
address: 10.0.0.0/16 |
| 68 |
cloud_context_profile: ctx_profile_1 |
| 69 |
state: present |
| 70 |
check_mode: true |
| 71 |
register: cm_non_primary_cidr |
| 72 |
|
| 73 |
- name: Create non_primary CIDR (normal_mode) |
| 74 |
cisco.aci.aci_cloud_cidr: |
| 75 |
<<: *aci_info |
| 76 |
tenant: ansible_test |
| 77 |
address: 10.0.0.0/16 |
| 78 |
cloud_context_profile: ctx_profile_1 |
| 79 |
state: present |
| 80 |
register: nm_non_primary_cidr |
| 81 |
|
| 82 |
- name: Verify cm_non_primary_cidr and nm_non_primary_cidr |
| 83 |
ansible.builtin.assert: |
| 84 |
that: |
| 85 |
- cm_non_primary_cidr is changed |
| 86 |
- nm_non_primary_cidr is changed |
| 87 |
- cm_non_primary_cidr.previous == [] |
| 88 |
- nm_non_primary_cidr.previous == [] |
| 89 |
- cm_non_primary_cidr.proposed.cloudCidr.attributes.addr == "10.0.0.0/16" |
| 90 |
- cm_non_primary_cidr.proposed.cloudCidr.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.0.0.0/16]" |
| 91 |
- cm_non_primary_cidr.proposed.cloudCidr.attributes.primary == "no" |
| 92 |
- nm_non_primary_cidr.current.0.cloudCidr.attributes.annotation == 'orchestrator:ansible' |
| 93 |
- nm_non_primary_cidr.current.0.cloudCidr.attributes.addr == "10.0.0.0/16" |
| 94 |
- nm_non_primary_cidr.current.0.cloudCidr.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.0.0.0/16]" |
| 95 |
- nm_non_primary_cidr.current.0.cloudCidr.attributes.primary == "no" |
| 96 |
|
| 97 |
- name: Create non_primary CIDR again |
| 98 |
cisco.aci.aci_cloud_cidr: |
| 99 |
<<: *aci_info |
| 100 |
tenant: ansible_test |
| 101 |
address: 10.0.0.0/16 |
| 102 |
cloud_context_profile: ctx_profile_1 |
| 103 |
state: present |
| 104 |
register: nm_non_primary_cidr_again |
| 105 |
|
| 106 |
- name: Verify nm_non_primary_cidr_again |
| 107 |
ansible.builtin.assert: |
| 108 |
that: |
| 109 |
- nm_non_primary_cidr_again is not changed |
| 110 |
- nm_non_primary_cidr_again.previous.0.cloudCidr.attributes.addr == "10.0.0.0/16" |
| 111 |
- nm_non_primary_cidr_again.previous.0.cloudCidr.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.0.0.0/16]" |
| 112 |
- nm_non_primary_cidr_again.previous.0.cloudCidr.attributes.primary == "no" |
| 113 |
- nm_non_primary_cidr_again.current.0.cloudCidr.attributes.addr == "10.0.0.0/16" |
| 114 |
- nm_non_primary_cidr_again.current.0.cloudCidr.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.0.0.0/16]" |
| 115 |
- nm_non_primary_cidr_again.current.0.cloudCidr.attributes.primary == "no" |
| 116 |
|
| 117 |
- name: Change primary CIDR to non_primary (check_mode) |
| 118 |
cisco.aci.aci_cloud_cidr: |
| 119 |
<<: *aci_info |
| 120 |
tenant: ansible_test |
| 121 |
address: 10.11.0.0/16 |
| 122 |
cloud_context_profile: ctx_profile_1 |
| 123 |
state: present |
| 124 |
check_mode: true |
| 125 |
register: cm_change_to_non_primary_cidr |
| 126 |
|
| 127 |
- name: Change primary CIDR to non_primary (normal_mode) |
| 128 |
cisco.aci.aci_cloud_cidr: |
| 129 |
<<: *aci_info |
| 130 |
tenant: ansible_test |
| 131 |
address: 10.11.0.0/16 |
| 132 |
cloud_context_profile: ctx_profile_1 |
| 133 |
state: present |
| 134 |
ignore_errors: true |
| 135 |
register: nm_change_to_non_primary_cidr |
| 136 |
|
| 137 |
- name: Verify cm_primary_cidr and nm_change_to_non_primary_cidr |
| 138 |
ansible.builtin.assert: |
| 139 |
that: |
| 140 |
- nm_change_to_non_primary_cidr.msg == "APIC Error 1{{':'}} Invalid Configuration {{':'}} Exactly one Primary CIDR expected for{{':'}} uni/tn-ansible_test/ctxprofile-ctx_profile_1, but found{{':'}} 0" |
| 141 |
- cm_change_to_non_primary_cidr.proposed.cloudCidr.attributes.primary == "no" |
| 142 |
- cm_change_to_non_primary_cidr.previous.0.cloudCidr.attributes.primary == cm_change_to_non_primary_cidr.current.0.cloudCidr.attributes.primary == "yes" |
| 143 |
|
| 144 |
- name: Remove primary CIDR (check_mode) |
| 145 |
cisco.aci.aci_cloud_cidr: |
| 146 |
<<: *aci_info |
| 147 |
tenant: ansible_test |
| 148 |
address: 10.11.0.0/16 |
| 149 |
cloud_context_profile: ctx_profile_1 |
| 150 |
state: absent |
| 151 |
check_mode: true |
| 152 |
register: cm_remove_primary_cidr |
| 153 |
|
| 154 |
- name: Remove primary CIDR (normal_mode) |
| 155 |
cisco.aci.aci_cloud_cidr: |
| 156 |
<<: *aci_info |
| 157 |
tenant: ansible_test |
| 158 |
address: 10.11.0.0/16 |
| 159 |
cloud_context_profile: ctx_profile_1 |
| 160 |
state: absent |
| 161 |
ignore_errors: true |
| 162 |
register: nm_remove_primary_cidr |
| 163 |
|
| 164 |
- name: Verify cm_remove_primary_cidr and nm_remove_primary_cidr |
| 165 |
ansible.builtin.assert: |
| 166 |
that: |
| 167 |
- nm_remove_primary_cidr.msg == "APIC Error 1{{':'}} Invalid Configuration {{':'}} Exactly one Primary CIDR expected for{{':'}} uni/tn-ansible_test/ctxprofile-ctx_profile_1, but found{{':'}} 0" |
| 168 |
- cm_remove_primary_cidr.proposed == {} |
| 169 |
- cm_remove_primary_cidr.previous.0.cloudCidr.attributes.primary == cm_remove_primary_cidr.current.0.cloudCidr.attributes.primary == "yes" |
| 170 |
|
| 171 |
- name: Create second non_primary CIDR |
| 172 |
cisco.aci.aci_cloud_cidr: |
| 173 |
<<: *aci_info |
| 174 |
tenant: ansible_test |
| 175 |
address: 10.18.0.0/16 |
| 176 |
cloud_context_profile: ctx_profile_1 |
| 177 |
state: present |
| 178 |
register: nm_add_second_non_primary_cidr |
| 179 |
|
| 180 |
- name: Verify nm_add_second_non_primary_cidr |
| 181 |
ansible.builtin.assert: |
| 182 |
that: |
| 183 |
- nm_add_second_non_primary_cidr is changed |
| 184 |
- nm_add_second_non_primary_cidr.previous == [] |
| 185 |
- nm_add_second_non_primary_cidr.current.0.cloudCidr.attributes.addr == "10.18.0.0/16" |
| 186 |
- nm_add_second_non_primary_cidr.current.0.cloudCidr.attributes.primary == "no" |
| 187 |
- nm_add_second_non_primary_cidr.current.0.cloudCidr.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.18.0.0/16]" |
| 188 |
|
| 189 |
- name: Change setting of second non_primary CIDR |
| 190 |
cisco.aci.aci_cloud_cidr: |
| 191 |
<<: *aci_info |
| 192 |
tenant: ansible_test |
| 193 |
cidr: 10.18.0.0/16 |
| 194 |
cloud_context_profile: ctx_profile_1 |
| 195 |
description: This is not a primary CIDR |
| 196 |
name_alias: cidr_block_range |
| 197 |
state: present |
| 198 |
register: change_non_primary_cidr |
| 199 |
|
| 200 |
- name: Verify change_non_primary_cidr |
| 201 |
ansible.builtin.assert: |
| 202 |
that: |
| 203 |
- change_non_primary_cidr is changed |
| 204 |
- change_non_primary_cidr.current.0.cloudCidr.attributes.addr == "10.18.0.0/16" |
| 205 |
- change_non_primary_cidr.current.0.cloudCidr.attributes.descr == "This is not a primary CIDR" |
| 206 |
- change_non_primary_cidr.current.0.cloudCidr.attributes.nameAlias == "cidr_block_range" |
| 207 |
- change_non_primary_cidr.current.0.cloudCidr.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.18.0.0/16]" |
| 208 |
|
| 209 |
- name: Query all CIDRs |
| 210 |
cisco.aci.aci_cloud_cidr: |
| 211 |
<<: *aci_info |
| 212 |
tenant: ansible_test |
| 213 |
cloud_context_profile: ctx_profile_1 |
| 214 |
state: query |
| 215 |
register: query_all |
| 216 |
|
| 217 |
- name: Verify query_all |
| 218 |
ansible.builtin.assert: |
| 219 |
that: |
| 220 |
- query_all is not changed |
| 221 |
- query_all.current.0.cloudCtxProfile.attributes.name == "ctx_profile_1" |
| 222 |
- query_all.current.0.cloudCtxProfile.children | length == 3 |
| 223 |
- query_all.current.0.cloudCtxProfile.children.0.cloudCidr.attributes.addr == "10.18.0.0/16" |
| 224 |
- query_all.current.0.cloudCtxProfile.children.0.cloudCidr.attributes.primary == "no" |
| 225 |
- query_all.current.0.cloudCtxProfile.children.1.cloudCidr.attributes.addr == "10.0.0.0/16" |
| 226 |
- query_all.current.0.cloudCtxProfile.children.1.cloudCidr.attributes.primary == "no" |
| 227 |
- query_all.current.0.cloudCtxProfile.children.2.cloudCidr.attributes.addr == "10.11.0.0/16" |
| 228 |
- query_all.current.0.cloudCtxProfile.children.2.cloudCidr.attributes.primary == "yes" |
| 229 |
|
| 230 |
- name: Query primary CIDR |
| 231 |
cisco.aci.aci_cloud_cidr: |
| 232 |
<<: *aci_info |
| 233 |
tenant: ansible_test |
| 234 |
cloud_context_profile: ctx_profile_1 |
| 235 |
address: 10.11.0.0/16 |
| 236 |
state: query |
| 237 |
register: query_primary |
| 238 |
|
| 239 |
- name: Verify query_primary |
| 240 |
ansible.builtin.assert: |
| 241 |
that: |
| 242 |
- query_primary is not changed |
| 243 |
- query_primary.current.0.cloudCidr.attributes.addr == "10.11.0.0/16" |
| 244 |
- query_primary.current.0.cloudCidr.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.11.0.0/16]" |
| 245 |
- query_primary.current.0.cloudCidr.attributes.primary == "yes" |
| 246 |
|
| 247 |
- name: Query non_primary CIDR |
| 248 |
cisco.aci.aci_cloud_cidr: |
| 249 |
<<: *aci_info |
| 250 |
tenant: ansible_test |
| 251 |
cloud_context_profile: ctx_profile_1 |
| 252 |
address: 10.0.0.0/16 |
| 253 |
state: query |
| 254 |
register: query_non_primary |
| 255 |
|
| 256 |
- name: Verify query_non_primary |
| 257 |
ansible.builtin.assert: |
| 258 |
that: |
| 259 |
- query_non_primary is not changed |
| 260 |
- query_non_primary.current.0.cloudCidr.attributes.addr == "10.0.0.0/16" |
| 261 |
- query_non_primary.current.0.cloudCidr.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.0.0.0/16]" |
| 262 |
- query_non_primary.current.0.cloudCidr.attributes.primary == "no" |
| 263 |
|
| 264 |
- name: Query non_exsisting CIDR |
| 265 |
cisco.aci.aci_cloud_cidr: |
| 266 |
<<: *aci_info |
| 267 |
tenant: ansible_test |
| 268 |
cloud_context_profile: ctx_profile_1 |
| 269 |
address: non_exsisting |
| 270 |
state: query |
| 271 |
ignore_errors: true |
| 272 |
register: query_non_existing |
| 273 |
|
| 274 |
- name: Verify query_non_existing |
| 275 |
ansible.builtin.assert: |
| 276 |
that: |
| 277 |
- query_non_existing.msg == "APIC Error 104{{':'}} Invalid RN cidr-[non_exsisting]" |
| 278 |
|
| 279 |
- name: Remove non_primary CIDR(check_mode) |
| 280 |
cisco.aci.aci_cloud_cidr: |
| 281 |
<<: *aci_info |
| 282 |
tenant: ansible_test |
| 283 |
address: 10.0.0.0/16 |
| 284 |
cloud_context_profile: ctx_profile_1 |
| 285 |
state: absent |
| 286 |
check_mode: true |
| 287 |
register: cm_remove_non_primary_cidr |
| 288 |
|
| 289 |
- name: Remove non_primary CIDR(normal_mode) |
| 290 |
cisco.aci.aci_cloud_cidr: |
| 291 |
<<: *aci_info |
| 292 |
tenant: ansible_test |
| 293 |
address: 10.0.0.0/16 |
| 294 |
cloud_context_profile: ctx_profile_1 |
| 295 |
state: absent |
| 296 |
register: nm_remove_non_primary_cidr |
| 297 |
|
| 298 |
- name: Verify cm_remove_non_primary_cidr and nm_remove_non_primary_cidr |
| 299 |
ansible.builtin.assert: |
| 300 |
that: |
| 301 |
- cm_remove_non_primary_cidr is changed |
| 302 |
- nm_remove_non_primary_cidr is changed |
| 303 |
- cm_remove_non_primary_cidr.proposed == {} |
| 304 |
- nm_remove_non_primary_cidr.current == [] |
| 305 |
- cm_remove_non_primary_cidr.previous.0.cloudCidr.attributes.addr == "10.0.0.0/16" |
| 306 |
- cm_remove_non_primary_cidr.previous.0.cloudCidr.attributes.primary == "no" |
| 307 |
- cm_remove_non_primary_cidr.previous.0.cloudCidr.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.0.0.0/16]" |
| 308 |
- nm_remove_non_primary_cidr.previous.0.cloudCidr.attributes.addr == "10.0.0.0/16" |
| 309 |
- nm_remove_non_primary_cidr.previous.0.cloudCidr.attributes.primary == "no" |
| 310 |
- nm_remove_non_primary_cidr.previous.0.cloudCidr.attributes.dn == "uni/tn-ansible_test/ctxprofile-ctx_profile_1/cidr-[10.0.0.0/16]" |