| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
- name: Test that we have an ACI APIC host, ACI username and ACI password |
| 8 |
ansible.builtin.fail: |
| 9 |
msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.' |
| 10 |
when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined |
| 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: debug |
| 22 |
|
| 23 |
- name: Query system information |
| 24 |
cisco.aci.aci_system: |
| 25 |
<<: *aci_info |
| 26 |
id: 1 |
| 27 |
state: query |
| 28 |
register: version |
| 29 |
|
| 30 |
- name: Verify Cloud and Non-Cloud Sites in use. |
| 31 |
ansible.builtin.include_tasks: ../../../../../../integration/targets/aci_cloud_provider/tasks/main.yml |
| 32 |
|
| 33 |
- name: ensure tenant does not exists |
| 34 |
cisco.aci.aci_tenant: &aci_tenant_absent |
| 35 |
<<: *aci_info |
| 36 |
state: absent |
| 37 |
tenant: ansible_test |
| 38 |
|
| 39 |
- name: Execute tasks only for non-cloud sites |
| 40 |
when: query_cloud.current == [] |
| 41 |
block: |
| 42 |
- name: ensure tenant exists for tests to kick off |
| 43 |
cisco.aci.aci_tenant: &aci_tenant_present |
| 44 |
<<: *aci_tenant_absent |
| 45 |
state: present |
| 46 |
tenant: ansible_test |
| 47 |
register: tenant_present |
| 48 |
|
| 49 |
- name: ensure ap exists for tests to kick off |
| 50 |
cisco.aci.aci_ap: &aci_ap_present |
| 51 |
<<: *aci_tenant_present |
| 52 |
ap: anstest |
| 53 |
register: ap_present |
| 54 |
|
| 55 |
- name: ensure epg exists for tests to kick off |
| 56 |
cisco.aci.aci_epg: &aci_epg_present |
| 57 |
<<: *aci_ap_present |
| 58 |
epg: anstest |
| 59 |
register: epg_present |
| 60 |
|
| 61 |
- name: create subnet - check mode works |
| 62 |
cisco.aci.aci_epg_subnet: &aci_subnet_present |
| 63 |
<<: *aci_epg_present |
| 64 |
state: present |
| 65 |
subnet_name: anstest |
| 66 |
gateway: 10.100.100.1 |
| 67 |
mask: 24 |
| 68 |
descr: Ansible Test |
| 69 |
check_mode: true |
| 70 |
register: create_check_mode |
| 71 |
|
| 72 |
- name: create subnet - creation works |
| 73 |
cisco.aci.aci_epg_subnet: |
| 74 |
<<: *aci_subnet_present |
| 75 |
register: create_subnet |
| 76 |
|
| 77 |
- name: create new subnet with IpDP_learning disabled - APIC version >= 5.0 |
| 78 |
cisco.aci.aci_epg_subnet: |
| 79 |
<<: *aci_epg_present |
| 80 |
state: present |
| 81 |
descr: Ansible Test |
| 82 |
gateway: 10.100.101.1 |
| 83 |
mask: 32 |
| 84 |
scope: [private, shared] |
| 85 |
route_profile: default |
| 86 |
route_profile_l3out: default |
| 87 |
subnet_control: no_default_gateway |
| 88 |
ip_data_plane_learning: disabled |
| 89 |
register: create_subnet2_5 |
| 90 |
when: version.current.0.topSystem.attributes.version is version('5', '>=') |
| 91 |
|
| 92 |
- name: create new subnet - creation works for APIC version < 5.0 |
| 93 |
cisco.aci.aci_epg_subnet: &aci_subnet2_present |
| 94 |
<<: *aci_epg_present |
| 95 |
state: present |
| 96 |
descr: Ansible Test |
| 97 |
gateway: 10.100.101.1 |
| 98 |
mask: 32 |
| 99 |
scope: [private, shared] |
| 100 |
route_profile: default |
| 101 |
route_profile_l3out: default |
| 102 |
subnet_control: no_default_gateway |
| 103 |
register: create_subnet2 |
| 104 |
when: version.current.0.topSystem.attributes.version is version('5', '<') |
| 105 |
|
| 106 |
- name: create subnet again with IpDP_learning disabled - idempotency works for APIC version >= 5 |
| 107 |
cisco.aci.aci_epg_subnet: |
| 108 |
<<: *aci_subnet2_present |
| 109 |
ip_data_plane_learning: disabled |
| 110 |
register: create_idempotency_5 |
| 111 |
when: version.current.0.topSystem.attributes.version is version('5', '>=') |
| 112 |
|
| 113 |
- name: create subnet again - idempotency works for APIC version < 5 |
| 114 |
cisco.aci.aci_epg_subnet: |
| 115 |
<<: *aci_subnet2_present |
| 116 |
register: create_idempotency |
| 117 |
when: version.current.0.topSystem.attributes.version is version('5', '<') |
| 118 |
|
| 119 |
- name: create subnet with bad scope - failure message works |
| 120 |
cisco.aci.aci_epg_subnet: |
| 121 |
<<: *aci_subnet_present |
| 122 |
scope: [private, public] |
| 123 |
register: create_bad_scope |
| 124 |
ignore_errors: true |
| 125 |
|
| 126 |
- name: create subnet without all necessary params - failure message works |
| 127 |
cisco.aci.aci_epg_subnet: |
| 128 |
<<: *aci_subnet_present |
| 129 |
epg: "{{ fake_var | default(omit) }}" |
| 130 |
register: create_incomplete_data |
| 131 |
ignore_errors: true |
| 132 |
|
| 133 |
- name: create subnet without valid mask - failure message works |
| 134 |
cisco.aci.aci_epg_subnet: |
| 135 |
<<: *aci_subnet_present |
| 136 |
mask: 130 |
| 137 |
register: create_wrong_mask |
| 138 |
ignore_errors: true |
| 139 |
|
| 140 |
- name: asserts for subnet creation tasks |
| 141 |
ansible.builtin.assert: |
| 142 |
that: |
| 143 |
- create_check_mode is changed |
| 144 |
- create_check_mode.sent.fvSubnet.attributes.descr == create_subnet.sent.fvSubnet.attributes.descr == 'Ansible Test' |
| 145 |
- create_check_mode.sent.fvSubnet.attributes.ip == create_subnet.sent.fvSubnet.attributes.ip == '10.100.100.1/24' |
| 146 |
- create_check_mode.sent.fvSubnet.attributes.name == create_subnet.sent.fvSubnet.attributes.name == 'anstest' |
| 147 |
- create_subnet is changed |
| 148 |
- create_subnet.current.0.fvSubnet.attributes.annotation == 'orchestrator:ansible' |
| 149 |
- create_subnet.previous == [] |
| 150 |
- create_bad_scope is failed |
| 151 |
- create_bad_scope.msg.startswith("Parameter 'scope' cannot be both 'private' and 'public'") |
| 152 |
- create_incomplete_data is failed |
| 153 |
- 'create_incomplete_data.msg == "state is present but all of the following are missing: epg"' |
| 154 |
- create_wrong_mask is failed |
| 155 |
- create_wrong_mask.msg == "Valid Subnet Masks are 0 to 32 for IPv4 Addresses and 0 to 128 for IPv6 addresses" |
| 156 |
|
| 157 |
- name: assert for subnet IpDPlearning tasks version >=5 |
| 158 |
ansible.builtin.assert: |
| 159 |
that: |
| 160 |
- create_subnet2_5 is changed |
| 161 |
- create_subnet2_5.current.0.fvSubnet.attributes.ctrl == 'no-default-gateway' |
| 162 |
- create_subnet2_5.sent == create_subnet2_5.proposed |
| 163 |
- create_subnet2_5.sent.fvSubnet.attributes.scope == "private,shared" |
| 164 |
- create_subnet2_5.sent.fvSubnet.children.0.fvRsBDSubnetToProfile.attributes.tnL3extOutName == 'default' |
| 165 |
- create_subnet2_5.sent.fvSubnet.children.0.fvRsBDSubnetToProfile.attributes.tnRtctrlProfileName == 'default' |
| 166 |
- create_idempotency_5 is not changed |
| 167 |
- create_idempotency_5.previous != [] |
| 168 |
- create_subnet.current.0.fvSubnet.attributes.ipDPLearning == 'enabled' |
| 169 |
- create_subnet2_5.current.0.fvSubnet.attributes.ipDPLearning == 'disabled' |
| 170 |
when: version.current.0.topSystem.attributes.version is version('5', '>=') |
| 171 |
|
| 172 |
- name: assert for subnet IpDPlearning tasks version < 5 |
| 173 |
ansible.builtin.assert: |
| 174 |
that: |
| 175 |
- create_subnet2 is changed |
| 176 |
- create_subnet2.current.0.fvSubnet.attributes.ctrl == 'no-default-gateway' |
| 177 |
- create_subnet2.sent == create_subnet2.proposed |
| 178 |
- create_subnet2.sent.fvSubnet.attributes.scope == "private,shared" |
| 179 |
- create_subnet2.sent.fvSubnet.children.0.fvRsBDSubnetToProfile.attributes.tnL3extOutName == 'default' |
| 180 |
- create_subnet2.sent.fvSubnet.children.0.fvRsBDSubnetToProfile.attributes.tnRtctrlProfileName == 'default' |
| 181 |
- create_idempotency is not changed |
| 182 |
- create_idempotency.previous != [] |
| 183 |
when: version.current.0.topSystem.attributes.version is version('5', '<') |
| 184 |
|
| 185 |
- name: get all in epg |
| 186 |
cisco.aci.aci_epg_subnet: |
| 187 |
<<: *aci_epg_present |
| 188 |
state: query |
| 189 |
register: get_all_epg |
| 190 |
|
| 191 |
- name: get specific subnet |
| 192 |
cisco.aci.aci_epg_subnet: |
| 193 |
<<: *aci_subnet_present |
| 194 |
state: query |
| 195 |
register: get_subnet |
| 196 |
|
| 197 |
- name: get all subnets matching gateway |
| 198 |
cisco.aci.aci_epg_subnet: |
| 199 |
<<: *aci_subnet_present |
| 200 |
state: query |
| 201 |
tenant: "{{ fake_var | default(omit) }}" |
| 202 |
ap: "{{ fake_var | default(omit) }}" |
| 203 |
epg: "{{ fake_var | default(omit) }}" |
| 204 |
register: get_subnets_gateway |
| 205 |
|
| 206 |
- name: asserts for query tasks |
| 207 |
ansible.builtin.assert: |
| 208 |
that: |
| 209 |
- get_all_epg is not changed |
| 210 |
- '"rsp-subtree-class=fvRsBDSubnetToProfile,fvRsNdPfxPol,fvSubnet" in get_all_epg.filter_string' |
| 211 |
- '"tn-ansible_test/ap-anstest/epg-anstest.json" in get_all_epg.url' |
| 212 |
- get_subnet is not changed |
| 213 |
- get_subnet.current | length == 1 |
| 214 |
- '"tn-ansible_test/ap-anstest/epg-anstest/subnet-[10.100.100.1/24].json" in get_subnet.url' |
| 215 |
- get_subnets_gateway is not changed |
| 216 |
- '"query-target-filter=eq(fvSubnet.ip,\"10.100.100.1/24\")" in get_subnets_gateway.filter_string' |
| 217 |
- '"class/fvSubnet.json" in get_subnets_gateway.url' |
| 218 |
|
| 219 |
- name: delete subnet - check mode works |
| 220 |
cisco.aci.aci_epg_subnet: |
| 221 |
<<: *aci_subnet_present |
| 222 |
state: absent |
| 223 |
check_mode: true |
| 224 |
register: delete_check_mode |
| 225 |
|
| 226 |
- name: delete subnet - delete works |
| 227 |
cisco.aci.aci_epg_subnet: |
| 228 |
<<: *aci_subnet_present |
| 229 |
state: absent |
| 230 |
register: delete_subnet |
| 231 |
|
| 232 |
- name: delete subnet - cleanup |
| 233 |
cisco.aci.aci_epg_subnet: |
| 234 |
<<: *aci_subnet2_present |
| 235 |
state: absent |
| 236 |
|
| 237 |
- name: delete subnet again - idempotency works |
| 238 |
cisco.aci.aci_epg_subnet: |
| 239 |
<<: *aci_subnet2_present |
| 240 |
state: absent |
| 241 |
register: delete_idempotency |
| 242 |
|
| 243 |
- name: asserts for deletion task |
| 244 |
ansible.builtin.assert: |
| 245 |
that: |
| 246 |
- delete_check_mode is changed |
| 247 |
- delete_check_mode.proposed == {} |
| 248 |
- delete_subnet is changed |
| 249 |
- delete_subnet.previous != [] |
| 250 |
- delete_subnet.method == "DELETE" |
| 251 |
- delete_idempotency is not changed |
| 252 |
- delete_idempotency.previous == [] |
| 253 |
|
| 254 |
- name: delete tenant - cleanup before ending tests |
| 255 |
cisco.aci.aci_tenant: |
| 256 |
<<: *aci_tenant_present |
| 257 |
state: absent |
| 258 |
when: tenant_present is changed |