| 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: create a snapshot - creation works |
| 12 |
cisco.aci.aci_config_snapshot: &create_snapshot |
| 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 |
export_policy: anstest |
| 21 |
include_secure: false |
| 22 |
format: json |
| 23 |
description: ansible test |
| 24 |
register: create |
| 25 |
|
| 26 |
- name: update snapshot to include secure and use xml - update works |
| 27 |
cisco.aci.aci_config_snapshot: |
| 28 |
<<: *create_snapshot |
| 29 |
max_count: 10 |
| 30 |
include_secure: true |
| 31 |
format: xml |
| 32 |
register: create_update |
| 33 |
|
| 34 |
- name: create a snapshot invalid max_count - error message |
| 35 |
cisco.aci.aci_config_snapshot: |
| 36 |
<<: *create_snapshot |
| 37 |
max_count: 11 |
| 38 |
ignore_errors: true |
| 39 |
register: invalid_max_count |
| 40 |
|
| 41 |
- name: create a snapshot invalid max_count - error message |
| 42 |
cisco.aci.aci_config_snapshot: |
| 43 |
<<: *create_snapshot |
| 44 |
export_policy: "{{ fake_var | default(omit) }}" |
| 45 |
ignore_errors: true |
| 46 |
register: missing_param |
| 47 |
|
| 48 |
- name: present assertion tests |
| 49 |
ansible.builtin.assert: |
| 50 |
that: |
| 51 |
- create is not failed |
| 52 |
- create is changed |
| 53 |
- create.sent.configExportP.attributes.adminSt == "triggered" |
| 54 |
- create_update is not failed |
| 55 |
- create_update is changed |
| 56 |
- create_update.current.0.configExportP.attributes.annotation == 'orchestrator:ansible' |
| 57 |
- create_update.sent.configExportP.attributes.adminSt == 'triggered' |
| 58 |
- create_update.sent.configExportP.attributes.format == 'xml' |
| 59 |
- create_update.sent.configExportP.attributes.includeSecureFields == 'yes' |
| 60 |
- invalid_max_count is failed |
| 61 |
- invalid_max_count.msg == "Parameter 'max_count' must be a number between 1 and 10" |
| 62 |
- missing_param is failed |
| 63 |
- 'missing_param.msg == "state is present but all of the following are missing: export_policy"' |
| 64 |
- create.job_details.attributes.dn == "uni/backupst/jobs-[uni/fabric/configexp-anstest]" |
| 65 |
- create.job_details.attributes.name == "anstest" |
| 66 |
- "'lastJobName' in create.job_details.attributes" |
| 67 |
|
| 68 |
- name: query with export_policy |
| 69 |
cisco.aci.aci_config_snapshot: &query_snapshot |
| 70 |
<<: *create_snapshot |
| 71 |
state: query |
| 72 |
register: query_export |
| 73 |
|
| 74 |
- name: generate snapshot name |
| 75 |
ansible.builtin.set_fact: |
| 76 |
test_snapshot: "{{ query_export.current.0.configSnapshotCont.children.0.configSnapshot.attributes.rn.strip('snapshot-') }}" |
| 77 |
|
| 78 |
- name: query with export_policy and snapshot |
| 79 |
cisco.aci.aci_config_snapshot: &query_both |
| 80 |
<<: *query_snapshot |
| 81 |
snapshot: "{{ test_snapshot }}" |
| 82 |
register: query_export_snapshot |
| 83 |
|
| 84 |
- name: query with snapshot - module add run- to snapshot |
| 85 |
cisco.aci.aci_config_snapshot: |
| 86 |
<<: *query_snapshot |
| 87 |
export_policy: "{{ fake_var | default(omit) }}" |
| 88 |
snapshot: "{{ test_snapshot.strip('run-') }}" |
| 89 |
register: query_snapshot |
| 90 |
|
| 91 |
- name: query no params |
| 92 |
cisco.aci.aci_config_snapshot: |
| 93 |
<<: *query_snapshot |
| 94 |
export_policy: "{{ fake_var | default(omit) }}" |
| 95 |
register: query_all |
| 96 |
|
| 97 |
- name: query assertion tests |
| 98 |
ansible.builtin.assert: |
| 99 |
that: |
| 100 |
- query_export is not failed |
| 101 |
- query_export is not changed |
| 102 |
- '"snapshots-[uni/fabric/configexp-anstest].json" in query_export.url' |
| 103 |
- query_export.current.0.configSnapshotCont.attributes.name == "anstest" |
| 104 |
- query_export.current.0.configSnapshotCont.children | length > 1 |
| 105 |
- query_export_snapshot is not failed |
| 106 |
- query_export_snapshot is not changed |
| 107 |
- '"snapshots-[uni/fabric/configexp-anstest]/snapshot-" in query_export_snapshot.url' |
| 108 |
- 'test_snapshot in query_export_snapshot.url' |
| 109 |
- query_export_snapshot.current | length == 1 |
| 110 |
- query_snapshot is not failed |
| 111 |
- query_snapshot is not changed |
| 112 |
- '"class/configSnapshot.json" in query_snapshot.url' |
| 113 |
- '"configSnapshot.name" in query_snapshot.filter_string' |
| 114 |
- 'test_snapshot in query_snapshot.filter_string' |
| 115 |
- query_all is not failed |
| 116 |
- query_all is not changed |
| 117 |
- '"class/configSnapshot.json" in query_all.url' |
| 118 |
- query_all.current | length > 1 |
| 119 |
|
| 120 |
- name: delete works |
| 121 |
cisco.aci.aci_config_snapshot: &delete |
| 122 |
<<: *query_both |
| 123 |
state: absent |
| 124 |
register: delete_snapshot |
| 125 |
|
| 126 |
- name: delete works - idempotency |
| 127 |
cisco.aci.aci_config_snapshot: |
| 128 |
<<: *delete |
| 129 |
register: delete_idempotent |
| 130 |
|
| 131 |
- name: delete missing param |
| 132 |
cisco.aci.aci_config_snapshot: |
| 133 |
<<: *delete |
| 134 |
snapshot: "{{ fake_var | default(omit) }}" |
| 135 |
ignore_errors: true |
| 136 |
register: delete_missing_param |
| 137 |
|
| 138 |
- name: absent assertion tests |
| 139 |
ansible.builtin.assert: |
| 140 |
that: |
| 141 |
- delete_snapshot is not failed |
| 142 |
- delete_snapshot is changed |
| 143 |
- delete_snapshot.sent.configSnapshot.attributes.retire == 'yes' |
| 144 |
- delete_snapshot.previous != [] |
| 145 |
- delete_snapshot.previous.0.configSnapshot.attributes.name == test_snapshot |
| 146 |
- delete_idempotent is not failed |
| 147 |
- delete_idempotent is not changed |
| 148 |
- delete_idempotent.previous == [] |
| 149 |
- delete_missing_param is failed |
| 150 |
- 'delete_missing_param.msg == "state is absent but all of the following are missing: snapshot"' |
| 151 |
|
| 152 |
|
| 153 |
- name: Set vars |
| 154 |
ansible.builtin.set_fact: |
| 155 |
aci_info: &aci_info |
| 156 |
host: "{{ aci_hostname }}" |
| 157 |
username: "{{ aci_username }}" |
| 158 |
validate_certs: "{{ aci_validate_certs | default(false) }}" |
| 159 |
use_ssl: "{{ aci_use_ssl | default(true) }}" |
| 160 |
use_proxy: "{{ aci_use_proxy | default(true) }}" |
| 161 |
output_level: debug |
| 162 |
|
| 163 |
- name: Add a user certificate to be used in the test |
| 164 |
cisco.aci.aci_aaa_user_certificate: |
| 165 |
<<: *aci_info |
| 166 |
password: "{{ aci_password }}" |
| 167 |
aaa_user: "{{ aci_username }}" |
| 168 |
name: admin |
| 169 |
certificate: "{{ lookup('file', 'pki/admin.crt') }}" |
| 170 |
state: present |
| 171 |
|
| 172 |
- name: create a snapshot using the private key |
| 173 |
cisco.aci.aci_config_snapshot: |
| 174 |
<<: *aci_info |
| 175 |
private_key: "{{ lookup('file', 'pki/admin.key') }}" |
| 176 |
export_policy: anstest |
| 177 |
include_secure: false |
| 178 |
format: json |
| 179 |
description: ansible test |
| 180 |
register: create_private_key |
| 181 |
|
| 182 |
- name: creation assertion tests with private key |
| 183 |
ansible.builtin.assert: |
| 184 |
that: |
| 185 |
- create_private_key is not failed |
| 186 |
- create_private_key is changed |
| 187 |
- create_private_key.sent.configExportP.attributes.adminSt == "triggered" |
| 188 |
|
| 189 |
- name: query the snapshot using the private key |
| 190 |
cisco.aci.aci_config_snapshot: |
| 191 |
<<: *aci_info |
| 192 |
private_key: "{{ lookup('file', 'pki/admin.key') }}" |
| 193 |
export_policy: anstest |
| 194 |
state: query |
| 195 |
register: query_private_key |
| 196 |
|
| 197 |
- name: generate snapshot name using query_private_key |
| 198 |
ansible.builtin.set_fact: |
| 199 |
test_snapshot_private_key: "{{ query_private_key.current.0.configSnapshotCont.children.0.configSnapshot.attributes.rn.strip('snapshot-') }}" |
| 200 |
|
| 201 |
- name: query assertion tests with private key |
| 202 |
ansible.builtin.assert: |
| 203 |
that: |
| 204 |
- query_private_key is not failed |
| 205 |
- query_private_key is not changed |
| 206 |
- '"snapshots-[uni/fabric/configexp-anstest].json" in query_private_key.url' |
| 207 |
|
| 208 |
- name: delete using the private key |
| 209 |
cisco.aci.aci_config_snapshot: |
| 210 |
<<: *aci_info |
| 211 |
private_key: "{{ lookup('file', 'pki/admin.key') }}" |
| 212 |
export_policy: anstest |
| 213 |
snapshot: "{{ test_snapshot_private_key }}" |
| 214 |
state: absent |
| 215 |
register: delete_snapshot_private_key |
| 216 |
|
| 217 |
- name: delete assertion tests with the private key |
| 218 |
ansible.builtin.assert: |
| 219 |
that: |
| 220 |
- delete_snapshot_private_key is not failed |
| 221 |
- delete_snapshot_private_key is changed |
| 222 |
|
| 223 |
- name: Remove the user certificate |
| 224 |
cisco.aci.aci_aaa_user_certificate: |
| 225 |
<<: *aci_info |
| 226 |
password: "{{ aci_password }}" |
| 227 |
aaa_user: "{{ aci_username }}" |
| 228 |
name: admin |
| 229 |
state: absent |