| 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 |
- name: ensure tenant exists for tests to kick off |
| 12 |
cisco.aci.aci_tenant: &aci_tenant_present |
| 13 |
host: "{{ aci_hostname }}" |
| 14 |
username: "{{ aci_username }}" |
| 15 |
password: "{{ aci_password }}" |
| 16 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 17 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 18 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 19 |
output_level: debug |
| 20 |
state: present |
| 21 |
tenant: ansible_test |
| 22 |
register: tenant_present |
| 23 |
|
| 24 |
- name: ensure vrf does not exist yet for tests to kick off |
| 25 |
cisco.aci.aci_vrf: |
| 26 |
<<: *aci_tenant_present |
| 27 |
vrf: "{{ item }}" |
| 28 |
state: absent |
| 29 |
with_items: |
| 30 |
- anstest |
| 31 |
- anstest2 |
| 32 |
|
| 33 |
- name: create vrf - check mode works |
| 34 |
cisco.aci.aci_vrf: &aci_vrf_present |
| 35 |
<<: *aci_tenant_present |
| 36 |
vrf: anstest |
| 37 |
description: Ansible Test |
| 38 |
check_mode: true |
| 39 |
register: vrf_present_check_mode |
| 40 |
|
| 41 |
- name: create vrf - creation works |
| 42 |
cisco.aci.aci_vrf: |
| 43 |
<<: *aci_vrf_present |
| 44 |
register: vrf_present |
| 45 |
|
| 46 |
- name: create vrf again - idempotency works |
| 47 |
cisco.aci.aci_vrf: |
| 48 |
<<: *aci_vrf_present |
| 49 |
register: vrf_present_idempotent |
| 50 |
|
| 51 |
- name: update vrf - update works |
| 52 |
cisco.aci.aci_vrf: |
| 53 |
<<: *aci_vrf_present |
| 54 |
description: Ansible Test Update |
| 55 |
policy_control_preference: unenforced |
| 56 |
register: vrf_update |
| 57 |
|
| 58 |
- name: create another vrf - check more params |
| 59 |
cisco.aci.aci_vrf: |
| 60 |
<<: *aci_vrf_present |
| 61 |
vrf: anstest2 |
| 62 |
policy_control_direction: egress |
| 63 |
preferred_group: enabled |
| 64 |
match_type: all |
| 65 |
ip_data_plane_learning: disabled |
| 66 |
register: vrf_present_2 |
| 67 |
|
| 68 |
- name: create vrf without all necessary params - failure message works |
| 69 |
cisco.aci.aci_vrf: |
| 70 |
<<: *aci_vrf_present |
| 71 |
tenant: "{{ fake_var | default(omit) }}" |
| 72 |
ignore_errors: true |
| 73 |
register: vrf_present_missing_param |
| 74 |
|
| 75 |
- name: present asserts |
| 76 |
ansible.builtin.assert: |
| 77 |
that: |
| 78 |
- vrf_present_check_mode is changed |
| 79 |
- vrf_present_check_mode.sent.fvCtx.attributes.descr == 'Ansible Test' |
| 80 |
- vrf_present_check_mode.sent.fvCtx.attributes.name == 'anstest' |
| 81 |
- vrf_present is changed |
| 82 |
- vrf_present.sent == vrf_present_check_mode.sent |
| 83 |
- vrf_present.current.0.fvCtx.attributes.annotation == 'orchestrator:ansible' |
| 84 |
- vrf_present.current.0.fvCtx.attributes.ipDataPlaneLearning == 'enabled' |
| 85 |
- vrf_present.previous == [] |
| 86 |
- vrf_present_idempotent is not changed |
| 87 |
- vrf_present_idempotent.previous != [] |
| 88 |
- vrf_update is changed |
| 89 |
- vrf_update.previous != [] |
| 90 |
- vrf_update.sent != vrf_update.proposed |
| 91 |
- vrf_update.sent.fvCtx.attributes.descr == 'Ansible Test Update' |
| 92 |
- vrf_update.sent.fvCtx.attributes.pcEnfPref == 'unenforced' |
| 93 |
- vrf_update.current.0.fvCtx.attributes.ipDataPlaneLearning == 'enabled' |
| 94 |
- vrf_present_2.sent.fvCtx.attributes.name == 'anstest2' |
| 95 |
- vrf_present_2.sent.fvCtx.attributes.pcEnfDir == 'egress' |
| 96 |
- vrf_present_2.sent.fvCtx.attributes.descr == 'Ansible Test' |
| 97 |
- vrf_present_2.current.0.fvCtx.attributes.ipDataPlaneLearning == 'disabled' |
| 98 |
- vrf_present_2.current.0.fvCtx.children.0.vzAny.attributes.matchT == 'All' |
| 99 |
- vrf_present_2.current.0.fvCtx.children.0.vzAny.attributes.prefGrMemb == 'enabled' |
| 100 |
- vrf_present_missing_param is failed |
| 101 |
- vrf_present_missing_param.msg == 'state is present but all of the following are missing{{":"}} tenant' |
| 102 |
|
| 103 |
- name: get all vrf |
| 104 |
cisco.aci.aci_vrf: &aci_query |
| 105 |
<<: *aci_tenant_present |
| 106 |
state: query |
| 107 |
tenant: "{{ fake_var | default(omit) }}" |
| 108 |
register: query_all |
| 109 |
|
| 110 |
- name: get all in tenant |
| 111 |
cisco.aci.aci_vrf: |
| 112 |
<<: *aci_query |
| 113 |
tenant: ansible_test |
| 114 |
register: query_tenant |
| 115 |
|
| 116 |
- name: get all with name |
| 117 |
cisco.aci.aci_vrf: |
| 118 |
<<: *aci_query |
| 119 |
vrf: anstest |
| 120 |
register: query_vrf_vrf |
| 121 |
|
| 122 |
- name: get vrf |
| 123 |
cisco.aci.aci_vrf: |
| 124 |
<<: *aci_vrf_present |
| 125 |
state: query |
| 126 |
register: query_vrf |
| 127 |
|
| 128 |
- name: query asserts |
| 129 |
ansible.builtin.assert: |
| 130 |
that: |
| 131 |
- query_all is not changed |
| 132 |
- query_all.current | length > 1 |
| 133 |
- query_all.current.0.fvCtx is defined |
| 134 |
- '"class/fvCtx.json" in query_all.url' |
| 135 |
- query_tenant is not changed |
| 136 |
- query_tenant.current | length == 1 |
| 137 |
- query_tenant.current.0.fvTenant.children | length == 2 |
| 138 |
- query_tenant.current.0.fvTenant.attributes.name == "ansible_test" |
| 139 |
- '"rsp-subtree-class=fvCtx" in query_tenant.filter_string' |
| 140 |
- '"tn-ansible_test.json" in query_tenant.url' |
| 141 |
- query_vrf_vrf is not changed |
| 142 |
- query_vrf_vrf.current != [] |
| 143 |
- query_vrf_vrf.current.0.fvCtx.attributes.name == "anstest" |
| 144 |
- '"query-target-filter=eq(fvCtx.name,\"anstest\")" in query_vrf_vrf.filter_string' |
| 145 |
- '"class/fvCtx.json" in query_vrf_vrf.url' |
| 146 |
- query_vrf is not changed |
| 147 |
- query_vrf.current | length == 1 |
| 148 |
- '"tn-ansible_test/ctx-anstest.json" in query_vrf.url' |
| 149 |
|
| 150 |
- name: delete vrf - check mode works |
| 151 |
cisco.aci.aci_vrf: &aci_vrf_absent |
| 152 |
<<: *aci_vrf_present |
| 153 |
state: absent |
| 154 |
check_mode: true |
| 155 |
register: vrf_absent_check_mode |
| 156 |
|
| 157 |
- name: delete vrf - delete works |
| 158 |
cisco.aci.aci_vrf: |
| 159 |
<<: *aci_vrf_absent |
| 160 |
register: vrf_absent |
| 161 |
|
| 162 |
- name: delete vrf again - idempotency works |
| 163 |
cisco.aci.aci_vrf: |
| 164 |
<<: *aci_vrf_absent |
| 165 |
register: vrf_absent_idempotent |
| 166 |
|
| 167 |
- name: delete vrf - cleanup |
| 168 |
cisco.aci.aci_vrf: |
| 169 |
<<: *aci_vrf_absent |
| 170 |
name: anstest2 |
| 171 |
|
| 172 |
- name: delete vrf missing param - fails properly |
| 173 |
cisco.aci.aci_vrf: |
| 174 |
<<: *aci_vrf_absent |
| 175 |
vrf: "{{ fakevar | default(omit) }}" |
| 176 |
ignore_errors: true |
| 177 |
register: vrf_absent_missing_param |
| 178 |
|
| 179 |
- name: asserts for deletion task |
| 180 |
ansible.builtin.assert: |
| 181 |
that: |
| 182 |
- vrf_absent_check_mode is changed |
| 183 |
- vrf_absent_check_mode.previous != [] |
| 184 |
- vrf_absent_check_mode.proposed == {} |
| 185 |
- vrf_absent is changed |
| 186 |
- vrf_absent.previous == vrf_absent_check_mode.previous |
| 187 |
- vrf_absent_idempotent is not changed |
| 188 |
- vrf_absent_idempotent.previous == [] |
| 189 |
- vrf_absent_missing_param is failed |
| 190 |
- 'vrf_absent_missing_param.msg == "state is absent but all of the following are missing: vrf"' |
| 191 |
|
| 192 |
- name: delete tenant - cleanup before ending tests |
| 193 |
cisco.aci.aci_tenant: |
| 194 |
<<: *aci_tenant_present |
| 195 |
state: absent |
| 196 |
when: tenant_present is changed |