| 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("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: Execute tasks only for ACI v5+ and non-cloud sites |
| 34 |
when: |
| 35 |
- version.current.0.topSystem.attributes.version is version('5', '>=') |
| 36 |
- query_cloud.current == [] |
| 37 |
block: |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
- name: Gather existing Contracts |
| 43 |
cisco.aci.aci_oob_contract: |
| 44 |
<<: *aci_info |
| 45 |
state: query |
| 46 |
register: all_oob_contracts |
| 47 |
|
| 48 |
- name: Delete all contracts except common-default |
| 49 |
cisco.aci.aci_oob_contract: |
| 50 |
<<: *aci_info |
| 51 |
contract: "{{item.vzOOBBrCP.attributes.name}}" |
| 52 |
state: absent |
| 53 |
loop: "{{all_oob_contracts.current}}" |
| 54 |
when: item.vzOOBBrCP.attributes.dn != "uni/tn-common/oobbrc-default" |
| 55 |
|
| 56 |
|
| 57 |
- name: Create OOB Contract (check_mode) |
| 58 |
cisco.aci.aci_oob_contract: &aci_oob_contract_present_CM |
| 59 |
<<: *aci_info |
| 60 |
contract: anstest |
| 61 |
description: Ansible Test |
| 62 |
state: present |
| 63 |
check_mode: true |
| 64 |
register: present_check_mode |
| 65 |
|
| 66 |
- name: Create OOB Contract |
| 67 |
cisco.aci.aci_oob_contract: &aci_oob_contract_present |
| 68 |
<<: *aci_oob_contract_present_CM |
| 69 |
state: "{{ fakevar | default(omit) }}" |
| 70 |
register: contract_present |
| 71 |
|
| 72 |
- name: Create OOB Contract again |
| 73 |
cisco.aci.aci_oob_contract: |
| 74 |
<<: *aci_oob_contract_present |
| 75 |
register: present_idempotent |
| 76 |
|
| 77 |
- name: Assert OOB Contracts were Created |
| 78 |
ansible.builtin.assert: |
| 79 |
that: |
| 80 |
- present_check_mode is changed |
| 81 |
- present_check_mode.previous == [] |
| 82 |
- present_check_mode.previous == present_check_mode.current |
| 83 |
- present_check_mode.proposed.vzOOBBrCP.attributes.name == 'anstest' |
| 84 |
- present_check_mode.proposed.vzOOBBrCP.attributes.descr == 'Ansible Test' |
| 85 |
- contract_present is changed |
| 86 |
- contract_present.previous == [] |
| 87 |
- contract_present.current.0.vzOOBBrCP.attributes.annotation == 'orchestrator:ansible' |
| 88 |
- contract_present.current.0.vzOOBBrCP.attributes.prio == 'unspecified' |
| 89 |
- contract_present.current.0.vzOOBBrCP.attributes.scope == 'context' |
| 90 |
- present_idempotent is not changed |
| 91 |
- present_idempotent.previous.0.vzOOBBrCP.attributes.descr == "Ansible Test" |
| 92 |
- present_idempotent.current.0.vzOOBBrCP.attributes.descr == "Ansible Test" |
| 93 |
- present_idempotent.previous.0.vzOOBBrCP.attributes.name == "anstest" |
| 94 |
- present_idempotent.current.0.vzOOBBrCP.attributes.name == "anstest" |
| 95 |
- present_idempotent.previous.0.vzOOBBrCP.attributes.prio == "unspecified" |
| 96 |
- present_idempotent.current.0.vzOOBBrCP.attributes.prio == "unspecified" |
| 97 |
- present_idempotent.previous.0.vzOOBBrCP.attributes.scope == "context" |
| 98 |
- present_idempotent.current.0.vzOOBBrCP.attributes.scope == "context" |
| 99 |
|
| 100 |
|
| 101 |
- name: Update OOB Contract |
| 102 |
cisco.aci.aci_oob_contract: |
| 103 |
<<: *aci_oob_contract_present |
| 104 |
scope: application-profile |
| 105 |
description: "Description altered" |
| 106 |
priority: "level1" |
| 107 |
register: update_contract |
| 108 |
|
| 109 |
- name: Missing Parameter contract_name - Failure Test |
| 110 |
cisco.aci.aci_oob_contract: |
| 111 |
<<: *aci_info |
| 112 |
ignore_errors: true |
| 113 |
register: present_missing_param |
| 114 |
|
| 115 |
- name: Assert OOB Contracts were updated |
| 116 |
ansible.builtin.assert: |
| 117 |
that: |
| 118 |
- update_contract is changed |
| 119 |
- update_contract.previous.0.vzOOBBrCP.attributes.scope == "context" |
| 120 |
- update_contract.current.0.vzOOBBrCP.attributes.scope == "application-profile" |
| 121 |
- update_contract.previous.0.vzOOBBrCP.attributes.descr == "Ansible Test" |
| 122 |
- update_contract.current.0.vzOOBBrCP.attributes.descr == "Description altered" |
| 123 |
- update_contract.previous.0.vzOOBBrCP.attributes.prio == "unspecified" |
| 124 |
- update_contract.current.0.vzOOBBrCP.attributes.prio == "level1" |
| 125 |
- present_missing_param is failed |
| 126 |
- 'present_missing_param.msg == "state is present but all of the following are missing: contract"' |
| 127 |
|
| 128 |
|
| 129 |
- name: Create another OOB Contract |
| 130 |
cisco.aci.aci_oob_contract: |
| 131 |
<<: *aci_oob_contract_present |
| 132 |
contract: anstest2 |
| 133 |
scope: vrf |
| 134 |
priority: level4 |
| 135 |
|
| 136 |
- name: Query OOB Contract |
| 137 |
cisco.aci.aci_oob_contract: &aci_oob_contract_query |
| 138 |
<<: *aci_oob_contract_present |
| 139 |
state: query |
| 140 |
register: query_contract |
| 141 |
|
| 142 |
- name: Query all OOB Contracts |
| 143 |
cisco.aci.aci_oob_contract: |
| 144 |
<<: *aci_oob_contract_query |
| 145 |
contract: "{{ fakevar | default(omit) }}" |
| 146 |
register: query_tenant |
| 147 |
|
| 148 |
- name: Assert OOB Contracts were queried |
| 149 |
ansible.builtin.assert: |
| 150 |
that: |
| 151 |
- query_contract is not changed |
| 152 |
- query_contract.current | length == 1 |
| 153 |
- query_contract.current.0.vzOOBBrCP.attributes.descr == "Description altered" |
| 154 |
- query_contract.current.0.vzOOBBrCP.attributes.dn == "uni/tn-mgmt/oobbrc-anstest" |
| 155 |
- query_contract.current.0.vzOOBBrCP.attributes.name == "anstest" |
| 156 |
- query_contract.current.0.vzOOBBrCP.attributes.prio == "level1" |
| 157 |
- query_contract.current.0.vzOOBBrCP.attributes.scope == "application-profile" |
| 158 |
- query_tenant is not changed |
| 159 |
- query_tenant.current | length > 2 |
| 160 |
- query_tenant.current.1.vzOOBBrCP.attributes.name == "anstest" |
| 161 |
- query_tenant.current.1.vzOOBBrCP.attributes.prio == "level1" |
| 162 |
- query_tenant.current.2.vzOOBBrCP.attributes.name == "anstest2" |
| 163 |
- query_tenant.current.2.vzOOBBrCP.attributes.scope == "context" |
| 164 |
- query_tenant.current.2.vzOOBBrCP.attributes.prio == "level4" |
| 165 |
|
| 166 |
|
| 167 |
- name: Delete OOB Contract (check_mode) |
| 168 |
cisco.aci.aci_oob_contract: &aci_oob_contract_absent |
| 169 |
<<: *aci_oob_contract_present |
| 170 |
state: absent |
| 171 |
check_mode: true |
| 172 |
register: absent_check_mode |
| 173 |
|
| 174 |
- name: Delete OOB Contract |
| 175 |
cisco.aci.aci_oob_contract: |
| 176 |
<<: *aci_oob_contract_absent |
| 177 |
register: contract_absent |
| 178 |
|
| 179 |
- name: Delete OOB Contract again |
| 180 |
cisco.aci.aci_oob_contract: |
| 181 |
<<: *aci_oob_contract_absent |
| 182 |
register: absent_idempotent |
| 183 |
|
| 184 |
- name: Delete other OOB Contract |
| 185 |
cisco.aci.aci_oob_contract: |
| 186 |
<<: *aci_oob_contract_absent |
| 187 |
contract: anstest2 |
| 188 |
|
| 189 |
- name: Missing Param contract_name - Failure Test |
| 190 |
cisco.aci.aci_oob_contract: |
| 191 |
<<: *aci_oob_contract_absent |
| 192 |
contract: "{{ fakevar | default(omit) }}" |
| 193 |
ignore_errors: true |
| 194 |
register: absent_missing_param |
| 195 |
|
| 196 |
- name: Assert all OOB Contracts were delete |
| 197 |
ansible.builtin.assert: |
| 198 |
that: |
| 199 |
- absent_check_mode is changed |
| 200 |
- absent_check_mode.previous != [] |
| 201 |
- absent_check_mode.current.0.vzOOBBrCP.attributes.descr == "Description altered" |
| 202 |
- absent_check_mode.current.0.vzOOBBrCP.attributes.name == "anstest" |
| 203 |
- absent_check_mode.current.0.vzOOBBrCP.attributes.prio == "level1" |
| 204 |
- absent_check_mode.current.0.vzOOBBrCP.attributes.scope == "application-profile" |
| 205 |
- absent_check_mode.proposed == {} |
| 206 |
- contract_absent is changed |
| 207 |
- contract_absent.previous == absent_check_mode.previous |
| 208 |
- contract_absent.previous.0.vzOOBBrCP.attributes.descr == "Description altered" |
| 209 |
- contract_absent.previous.0.vzOOBBrCP.attributes.name == "anstest" |
| 210 |
- contract_absent.previous.0.vzOOBBrCP.attributes.prio == "level1" |
| 211 |
- contract_absent.previous.0.vzOOBBrCP.attributes.scope == "application-profile" |
| 212 |
- contract_absent.current == [] |
| 213 |
- absent_idempotent is not changed |
| 214 |
- absent_idempotent.previous == [] |
| 215 |
- absent_idempotent.current == [] |
| 216 |
- absent_missing_param is failed |
| 217 |
- 'absent_missing_param.msg == "state is absent but all of the following are missing: contract"' |