| 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: Query system information |
| 24 |
cisco.aci.aci_system: |
| 25 |
<<: *aci_info |
| 26 |
id: 1 |
| 27 |
state: query |
| 28 |
register: version |
| 29 |
|
| 30 |
- name: Ensure an anstest_role aaa role does not exists |
| 31 |
cisco.aci.aci_aaa_role: &anstest_role_absent |
| 32 |
<<: *aci_info |
| 33 |
name: anstest_role |
| 34 |
state: absent |
| 35 |
|
| 36 |
- name: Add an anstest_role aaa role with check mode |
| 37 |
cisco.aci.aci_aaa_role: &cm_anstest_role_present |
| 38 |
<<: *anstest_role_absent |
| 39 |
priv: aaa |
| 40 |
state: present |
| 41 |
check_mode: true |
| 42 |
register: cm_anstest_role_present |
| 43 |
|
| 44 |
- name: Assertions check for add an anstest_role aaa role with check mode |
| 45 |
ansible.builtin.assert: |
| 46 |
that: |
| 47 |
- cm_anstest_role_present is changed |
| 48 |
- cm_anstest_role_present.current | length == 0 |
| 49 |
- cm_anstest_role_present.previous | length == 0 |
| 50 |
- cm_anstest_role_present.sent.aaaRole.attributes.name == 'anstest_role' |
| 51 |
- cm_anstest_role_present.sent.aaaRole.attributes.priv == 'aaa' |
| 52 |
|
| 53 |
- name: Add an anstest_role aaa role with normal mode |
| 54 |
cisco.aci.aci_aaa_role: &nm_anstest_role_present |
| 55 |
<<: *cm_anstest_role_present |
| 56 |
register: nm_anstest_role_present |
| 57 |
|
| 58 |
- name: Assertions check for add an anstest_role aaa role with normal mode |
| 59 |
ansible.builtin.assert: |
| 60 |
that: |
| 61 |
- nm_anstest_role_present is changed |
| 62 |
- nm_anstest_role_present.current | length == 1 |
| 63 |
- nm_anstest_role_present.previous | length == 0 |
| 64 |
- nm_anstest_role_present.current.0.aaaRole.attributes.name == 'anstest_role' |
| 65 |
- nm_anstest_role_present.current.0.aaaRole.attributes.priv == 'aaa' |
| 66 |
|
| 67 |
- name: Add an anstest_role aaa role with normal mode - idempotency works |
| 68 |
cisco.aci.aci_aaa_role: |
| 69 |
<<: *nm_anstest_role_present |
| 70 |
register: idempotency_anstest_role_present |
| 71 |
|
| 72 |
- name: Idempotency assertions check for add an anstest_role aaa role with normal mode |
| 73 |
ansible.builtin.assert: |
| 74 |
that: |
| 75 |
- idempotency_anstest_role_present is not changed |
| 76 |
- idempotency_anstest_role_present.current | length == 1 |
| 77 |
- idempotency_anstest_role_present.previous | length == 1 |
| 78 |
- idempotency_anstest_role_present.current.0.aaaRole.attributes.name == 'anstest_role' |
| 79 |
- idempotency_anstest_role_present.previous.0.aaaRole.attributes.name == 'anstest_role' |
| 80 |
- idempotency_anstest_role_present.current.0.aaaRole.attributes.priv == 'aaa' |
| 81 |
- idempotency_anstest_role_present.previous.0.aaaRole.attributes.priv == 'aaa' |
| 82 |
|
| 83 |
- name: Update an anstest_role with list of privileges |
| 84 |
cisco.aci.aci_aaa_role: |
| 85 |
<<: *nm_anstest_role_present |
| 86 |
priv: [ "admin", "aaa", "tenant-connectivity"] |
| 87 |
register: anstest_role_with_list_priv |
| 88 |
|
| 89 |
- name: Assertions check for update an anstest_role with list of privileges |
| 90 |
ansible.builtin.assert: |
| 91 |
that: |
| 92 |
- anstest_role_with_list_priv is changed |
| 93 |
- anstest_role_with_list_priv.current | length == 1 |
| 94 |
- anstest_role_with_list_priv.previous | length == 1 |
| 95 |
- anstest_role_with_list_priv.current.0.aaaRole.attributes.name == 'anstest_role' |
| 96 |
- anstest_role_with_list_priv.previous.0.aaaRole.attributes.name == 'anstest_role' |
| 97 |
- anstest_role_with_list_priv.previous.0.aaaRole.attributes.priv == 'aaa' |
| 98 |
|
| 99 |
- name: Assertions check for anstest_role_with_list_priv on v4.2 or earlier |
| 100 |
ansible.builtin.assert: |
| 101 |
that: |
| 102 |
- anstest_role_with_list_priv.current.0.aaaRole.attributes.priv == 'aaa,admin' |
| 103 |
when: version.current.0.topSystem.attributes.version is version('5', '<') |
| 104 |
|
| 105 |
- name: Assertions check for anstest_role_with_list_priv on v5+ |
| 106 |
ansible.builtin.assert: |
| 107 |
that: |
| 108 |
- anstest_role_with_list_priv.current.0.aaaRole.attributes.priv == 'aaa,admin,tenant-connectivity' |
| 109 |
when: version.current.0.topSystem.attributes.version is version('5', '>=') |
| 110 |
|
| 111 |
|
| 112 |
- name: Update an anstest_role with admin privilege |
| 113 |
cisco.aci.aci_aaa_role: |
| 114 |
<<: *nm_anstest_role_present |
| 115 |
priv: "admin" |
| 116 |
register: anstest_role_with_valid_priv |
| 117 |
|
| 118 |
- name: Assertions check for update an anstest_role with admin privilege |
| 119 |
ansible.builtin.assert: |
| 120 |
that: |
| 121 |
- anstest_role_with_valid_priv is changed |
| 122 |
- anstest_role_with_valid_priv.current | length == 1 |
| 123 |
- anstest_role_with_valid_priv.previous | length == 1 |
| 124 |
- anstest_role_with_valid_priv.current.0.aaaRole.attributes.name == 'anstest_role' |
| 125 |
- anstest_role_with_valid_priv.previous.0.aaaRole.attributes.name == 'anstest_role' |
| 126 |
- anstest_role_with_valid_priv.current.0.aaaRole.attributes.priv == 'admin' |
| 127 |
|
| 128 |
- name: Assertions check for anstest_role_with_valid_priv on v4.2 or earlier |
| 129 |
ansible.builtin.assert: |
| 130 |
that: |
| 131 |
- anstest_role_with_valid_priv.previous.0.aaaRole.attributes.priv == 'aaa,admin' |
| 132 |
when: version.current.0.topSystem.attributes.version is version('5', '<') |
| 133 |
|
| 134 |
- name: Assertions check for anstest_role_with_valid_priv on v5+ |
| 135 |
ansible.builtin.assert: |
| 136 |
that: |
| 137 |
- anstest_role_with_valid_priv.previous.0.aaaRole.attributes.priv == 'aaa,admin,tenant-connectivity' |
| 138 |
when: version.current.0.topSystem.attributes.version is version('5', '>=') |
| 139 |
|
| 140 |
- name: Update an anstest_role with invalid list of privileges |
| 141 |
cisco.aci.aci_aaa_role: |
| 142 |
<<: *nm_anstest_role_present |
| 143 |
priv: [ "admin", "aaa", "tenant-connectivity123"] |
| 144 |
register: anstest_role_with_invalid_list_priv |
| 145 |
ignore_errors: true |
| 146 |
|
| 147 |
- name: Update an anstest_role with invalid privilege |
| 148 |
cisco.aci.aci_aaa_role: |
| 149 |
<<: *nm_anstest_role_present |
| 150 |
priv: "admin123" |
| 151 |
register: anstest_role_with_invalid_priv |
| 152 |
ignore_errors: true |
| 153 |
|
| 154 |
- name: Assertions check for query a aaa role with name |
| 155 |
ansible.builtin.assert: |
| 156 |
that: |
| 157 |
- anstest_role_with_invalid_list_priv.msg.startswith("value of privileges must be one or more of") |
| 158 |
- anstest_role_with_invalid_priv.msg.startswith("value of privileges must be one or more of") |
| 159 |
|
| 160 |
- name: Query an aaa role with name |
| 161 |
cisco.aci.aci_aaa_role: |
| 162 |
<<: *aci_info |
| 163 |
name: anstest_role |
| 164 |
state: query |
| 165 |
register: anstest_role_query_result |
| 166 |
|
| 167 |
- name: Assertions check for query a aaa role with name |
| 168 |
ansible.builtin.assert: |
| 169 |
that: |
| 170 |
- anstest_role_query_result is not changed |
| 171 |
- anstest_role_query_result.current | length == 1 |
| 172 |
- anstest_role_query_result.current.0.aaaRole.attributes.name == 'anstest_role' |
| 173 |
- anstest_role_query_result.current.0.aaaRole.attributes.priv == 'admin' |
| 174 |
|
| 175 |
- name: Query all aaa roles |
| 176 |
cisco.aci.aci_aaa_role: |
| 177 |
<<: *aci_info |
| 178 |
state: query |
| 179 |
register: query_all_roles |
| 180 |
|
| 181 |
- name: Assertions check for query all aaa roles |
| 182 |
ansible.builtin.assert: |
| 183 |
that: |
| 184 |
- query_all_roles is not changed |
| 185 |
- query_all_roles.current | length >= 1 |
| 186 |
|
| 187 |
- name: Remove an anstest_role aaa role with check mode |
| 188 |
cisco.aci.aci_aaa_role: &cm_anstest_role_absent |
| 189 |
<<: *nm_anstest_role_present |
| 190 |
state: absent |
| 191 |
check_mode: true |
| 192 |
register: cm_anstest_role_absent |
| 193 |
|
| 194 |
- name: Assertions check for remove an anstest_role aaa role with check mode |
| 195 |
ansible.builtin.assert: |
| 196 |
that: |
| 197 |
- cm_anstest_role_absent is changed |
| 198 |
- cm_anstest_role_absent.current | length == 1 |
| 199 |
- cm_anstest_role_absent.previous | length == 1 |
| 200 |
- cm_anstest_role_absent.current.0.aaaRole.attributes.name == 'anstest_role' |
| 201 |
- cm_anstest_role_absent.previous.0.aaaRole.attributes.name == 'anstest_role' |
| 202 |
- cm_anstest_role_absent.current.0.aaaRole.attributes.priv == 'admin' |
| 203 |
- cm_anstest_role_absent.previous.0.aaaRole.attributes.priv == 'admin' |
| 204 |
|
| 205 |
- name: Remove an anstest_role aaa role with normal mode |
| 206 |
cisco.aci.aci_aaa_role: &nm_anstest_role_absent |
| 207 |
<<: *cm_anstest_role_absent |
| 208 |
register: nm_anstest_role_absent |
| 209 |
|
| 210 |
- name: Assertions check for remove an anstest_role aaa role with normal mode |
| 211 |
ansible.builtin.assert: |
| 212 |
that: |
| 213 |
- nm_anstest_role_absent is changed |
| 214 |
- nm_anstest_role_absent.current | length == 0 |
| 215 |
- nm_anstest_role_absent.previous | length == 1 |
| 216 |
- nm_anstest_role_absent.previous.0.aaaRole.attributes.name == 'anstest_role' |
| 217 |
- nm_anstest_role_absent.previous.0.aaaRole.attributes.priv == 'admin' |
| 218 |
|
| 219 |
- name: Remove an anstest_role aaa role with normal mode - idempotency works |
| 220 |
cisco.aci.aci_aaa_role: |
| 221 |
<<: *nm_anstest_role_absent |
| 222 |
register: idempotency_anstest_role_absent |
| 223 |
|
| 224 |
- name: Idempotency assertions check for remove an anstest_role aaa role with normal mode |
| 225 |
ansible.builtin.assert: |
| 226 |
that: |
| 227 |
- idempotency_anstest_role_absent is not changed |
| 228 |
- idempotency_anstest_role_absent.current | length == 0 |
| 229 |
- idempotency_anstest_role_absent.previous | length == 0 |