| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
- name: Test that we have an ACI MultiSite host, username and password |
| 7 |
ansible.builtin.fail: |
| 8 |
msg: "Please define the following variables: mso_hostname, mso_username and mso_password." |
| 9 |
when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined |
| 10 |
|
| 11 |
- name: Set vars |
| 12 |
ansible.builtin.set_fact: |
| 13 |
mso_info: &mso_info |
| 14 |
host: "{{ mso_hostname }}" |
| 15 |
username: "{{ mso_username }}" |
| 16 |
password: "{{ mso_password }}" |
| 17 |
validate_certs: "{{ mso_validate_certs | default(false) }}" |
| 18 |
use_ssl: "{{ mso_use_ssl | default(true) }}" |
| 19 |
use_proxy: "{{ mso_use_proxy | default(true) }}" |
| 20 |
output_level: '{{ mso_output_level | default("debug") }}' |
| 21 |
|
| 22 |
|
| 23 |
- name: Query MSO version |
| 24 |
cisco.mso.mso_version: |
| 25 |
<<: *mso_info |
| 26 |
state: query |
| 27 |
register: version |
| 28 |
|
| 29 |
- name: Execute tasks only for NDO version >= 4.3 |
| 30 |
when: version.current.version is version('4.3', '>=') |
| 31 |
block: |
| 32 |
|
| 33 |
- name: Ensure Fabric Policy template does not exist |
| 34 |
cisco.mso.ndo_template: &rm_fabric_policy_template |
| 35 |
<<: *mso_info |
| 36 |
template: ansible_fabric_policy_template |
| 37 |
template_type: fabric_policy |
| 38 |
state: absent |
| 39 |
|
| 40 |
- name: Ensure Fabric Policy template exist |
| 41 |
cisco.mso.ndo_template: |
| 42 |
<<: *rm_fabric_policy_template |
| 43 |
state: present |
| 44 |
register: fabric_policy_template |
| 45 |
|
| 46 |
- name: Ensure MACsec policies exists |
| 47 |
cisco.mso.ndo_macsec_policy: |
| 48 |
<<: *mso_info |
| 49 |
template: ansible_fabric_policy_template |
| 50 |
name: "{{ item }}" |
| 51 |
state: present |
| 52 |
loop: |
| 53 |
- macsec_policy_1 |
| 54 |
- macsec_policy_2 |
| 55 |
register: macsec_policies |
| 56 |
|
| 57 |
- name: Ensure NTP Policy policies exists |
| 58 |
cisco.mso.ndo_ntp_policy: |
| 59 |
<<: *mso_info |
| 60 |
template: ansible_fabric_policy_template |
| 61 |
name: "{{ item }}" |
| 62 |
state: present |
| 63 |
loop: |
| 64 |
- ntp_policy_1 |
| 65 |
- ntp_policy_2 |
| 66 |
register: ntp_policies |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
- name: Create Pod Settings (check_mode) |
| 71 |
cisco.mso.ndo_pod_settings: &create_pod_settings |
| 72 |
<<: *mso_info |
| 73 |
template: ansible_fabric_policy_template |
| 74 |
name: ansible_pod_settings_1 |
| 75 |
state: present |
| 76 |
register: cm_create_pod_settings |
| 77 |
check_mode: true |
| 78 |
|
| 79 |
- name: Create Pod Settings |
| 80 |
cisco.mso.ndo_pod_settings: |
| 81 |
<<: *create_pod_settings |
| 82 |
register: nm_create_pod_settings |
| 83 |
|
| 84 |
- name: Create Pod Settings again |
| 85 |
cisco.mso.ndo_pod_settings: |
| 86 |
<<: *create_pod_settings |
| 87 |
register: nm_create_pod_settings_again |
| 88 |
|
| 89 |
- name: Assert Pod Settings creation |
| 90 |
ansible.builtin.assert: |
| 91 |
that: |
| 92 |
- cm_create_pod_settings is changed |
| 93 |
- cm_create_pod_settings.previous == {} |
| 94 |
- cm_create_pod_settings.proposed == cm_create_pod_settings.current |
| 95 |
- cm_create_pod_settings.current.name == 'ansible_pod_settings_1' |
| 96 |
- cm_create_pod_settings.current.templateName == 'ansible_fabric_policy_template' |
| 97 |
- cm_create_pod_settings.current.templateId is defined |
| 98 |
- cm_create_pod_settings.current.uuid is not defined |
| 99 |
- nm_create_pod_settings is changed |
| 100 |
- nm_create_pod_settings.previous == {} |
| 101 |
- nm_create_pod_settings.proposed != nm_create_pod_settings.current |
| 102 |
- nm_create_pod_settings.current.name == 'ansible_pod_settings_1' |
| 103 |
- nm_create_pod_settings.current.templateName == 'ansible_fabric_policy_template' |
| 104 |
- nm_create_pod_settings.current.templateId is defined |
| 105 |
- nm_create_pod_settings.current.uuid is defined |
| 106 |
- nm_create_pod_settings_again is not changed |
| 107 |
- nm_create_pod_settings_again.previous == nm_create_pod_settings_again.current == nm_create_pod_settings.current |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
- name: Update Pod Settings (check_mode) |
| 112 |
cisco.mso.ndo_pod_settings: &update_pod_settings |
| 113 |
<<: *create_pod_settings |
| 114 |
name: ansible_pod_settings_1 |
| 115 |
description: Updated Pod Settings |
| 116 |
macsec_policy: |
| 117 |
name: macsec_policy_1 |
| 118 |
ntp_policy: |
| 119 |
name: ntp_policy_1 |
| 120 |
register: cm_update_pod_settings |
| 121 |
check_mode: true |
| 122 |
|
| 123 |
- name: Update Pod Settings |
| 124 |
cisco.mso.ndo_pod_settings: |
| 125 |
<<: *update_pod_settings |
| 126 |
register: nm_update_pod_settings |
| 127 |
|
| 128 |
- name: Update Pod Settings again |
| 129 |
cisco.mso.ndo_pod_settings: |
| 130 |
<<: *update_pod_settings |
| 131 |
register: nm_update_pod_settings_again |
| 132 |
|
| 133 |
- name: Assert Pod Settings update |
| 134 |
ansible.builtin.assert: |
| 135 |
that: |
| 136 |
- cm_update_pod_settings is changed |
| 137 |
- cm_update_pod_settings.previous.name == 'ansible_pod_settings_1' |
| 138 |
- cm_update_pod_settings.previous.templateName == 'ansible_fabric_policy_template' |
| 139 |
- cm_update_pod_settings.previous.templateId is defined |
| 140 |
- cm_update_pod_settings.previous.uuid is defined |
| 141 |
- cm_update_pod_settings.previous.fabricMACsec is not defined |
| 142 |
- cm_update_pod_settings.previous.ntp is not defined |
| 143 |
- cm_update_pod_settings.previous != cm_update_pod_settings.current |
| 144 |
- cm_update_pod_settings.proposed == cm_update_pod_settings.current |
| 145 |
- cm_update_pod_settings.current.name == 'ansible_pod_settings_1' |
| 146 |
- cm_update_pod_settings.current.templateName == 'ansible_fabric_policy_template' |
| 147 |
- cm_update_pod_settings.current.templateId is defined |
| 148 |
- cm_update_pod_settings.current.description == 'Updated Pod Settings' |
| 149 |
- cm_update_pod_settings.current.fabricMACsecName == 'macsec_policy_1' |
| 150 |
- cm_update_pod_settings.current.ntpName == 'ntp_policy_1' |
| 151 |
- cm_update_pod_settings.current.uuid is defined |
| 152 |
- cm_update_pod_settings.current.fabricMACsec is defined |
| 153 |
- cm_update_pod_settings.current.ntp is defined |
| 154 |
- nm_update_pod_settings is changed |
| 155 |
- nm_update_pod_settings.previous.name == 'ansible_pod_settings_1' |
| 156 |
- nm_update_pod_settings.previous.templateName == 'ansible_fabric_policy_template' |
| 157 |
- nm_update_pod_settings.previous.templateId is defined |
| 158 |
- nm_update_pod_settings.previous.uuid is defined |
| 159 |
- nm_update_pod_settings.previous.fabricMACsec is not defined |
| 160 |
- nm_update_pod_settings.previous.ntp is not defined |
| 161 |
- nm_update_pod_settings.proposed == nm_update_pod_settings.current |
| 162 |
- nm_update_pod_settings.current.name == 'ansible_pod_settings_1' |
| 163 |
- nm_update_pod_settings.current.templateName == 'ansible_fabric_policy_template' |
| 164 |
- nm_update_pod_settings.current.templateId is defined |
| 165 |
- nm_update_pod_settings.current.description == 'Updated Pod Settings' |
| 166 |
- nm_update_pod_settings.current.fabricMACsecName == 'macsec_policy_1' |
| 167 |
- nm_update_pod_settings.current.ntpName == 'ntp_policy_1' |
| 168 |
- nm_update_pod_settings.current.uuid is defined |
| 169 |
- nm_update_pod_settings.current.fabricMACsec is defined |
| 170 |
- nm_update_pod_settings.current.ntp is defined |
| 171 |
- nm_update_pod_settings_again is not changed |
| 172 |
- nm_update_pod_settings_again.previous == nm_update_pod_settings_again.current == nm_update_pod_settings.current |
| 173 |
|
| 174 |
- name: Update MACsec and NTP policies with UUID |
| 175 |
cisco.mso.ndo_pod_settings: |
| 176 |
<<: *create_pod_settings |
| 177 |
name: ansible_pod_settings_1 |
| 178 |
macsec_policy_uuid: "{{ macsec_policies.results[1].current.uuid }}" |
| 179 |
ntp_policy_uuid: "{{ ntp_policies.results[1].current.uuid }}" |
| 180 |
register: nm_update_pod_settings_with_uuid |
| 181 |
|
| 182 |
- name: Assert Pod Settings update with UUID |
| 183 |
ansible.builtin.assert: |
| 184 |
that: |
| 185 |
- nm_update_pod_settings_with_uuid is changed |
| 186 |
- nm_update_pod_settings_with_uuid.previous.name == 'ansible_pod_settings_1' |
| 187 |
- nm_update_pod_settings_with_uuid.previous.fabricMACsecName == 'macsec_policy_1' |
| 188 |
- nm_update_pod_settings_with_uuid.previous.ntpName == 'ntp_policy_1' |
| 189 |
- nm_update_pod_settings_with_uuid.previous.uuid is defined |
| 190 |
- nm_update_pod_settings_with_uuid.previous.fabricMACsec is defined |
| 191 |
- nm_update_pod_settings_with_uuid.previous.ntp is defined |
| 192 |
- nm_update_pod_settings_with_uuid.proposed == nm_update_pod_settings_with_uuid.current |
| 193 |
- nm_update_pod_settings_with_uuid.current.description == 'Updated Pod Settings' |
| 194 |
- nm_update_pod_settings_with_uuid.current.fabricMACsecName == 'macsec_policy_2' |
| 195 |
- nm_update_pod_settings_with_uuid.current.ntpName == 'ntp_policy_2' |
| 196 |
- nm_update_pod_settings_with_uuid.current.uuid is defined |
| 197 |
- nm_update_pod_settings_with_uuid.current.fabricMACsec is defined |
| 198 |
- nm_update_pod_settings_with_uuid.current.ntp is defined |
| 199 |
|
| 200 |
- name: Update description to empty string |
| 201 |
cisco.mso.ndo_pod_settings: |
| 202 |
<<: *create_pod_settings |
| 203 |
description: "" |
| 204 |
register: nm_update_pod_settings_empty_description |
| 205 |
|
| 206 |
- name: Assert Pod Settings update with empty description |
| 207 |
ansible.builtin.assert: |
| 208 |
that: |
| 209 |
- nm_update_pod_settings_empty_description is changed |
| 210 |
- nm_update_pod_settings_empty_description.previous.name == 'ansible_pod_settings_1' |
| 211 |
- nm_update_pod_settings_empty_description.previous.description == 'Updated Pod Settings' |
| 212 |
- nm_update_pod_settings_empty_description.previous.fabricMACsecName == 'macsec_policy_2' |
| 213 |
- nm_update_pod_settings_empty_description.previous.ntpName == 'ntp_policy_2' |
| 214 |
- nm_update_pod_settings_empty_description.previous.uuid is defined |
| 215 |
- nm_update_pod_settings_empty_description.previous.fabricMACsec is defined |
| 216 |
- nm_update_pod_settings_empty_description.previous.ntp is defined |
| 217 |
- nm_update_pod_settings_empty_description.proposed == nm_update_pod_settings_empty_description.current |
| 218 |
- nm_update_pod_settings_empty_description.current.description == '' |
| 219 |
- nm_update_pod_settings_empty_description.current.fabricMACsecName == 'macsec_policy_2' |
| 220 |
- nm_update_pod_settings_empty_description.current.ntpName == 'ntp_policy_2' |
| 221 |
- nm_update_pod_settings_empty_description.current.uuid is defined |
| 222 |
- nm_update_pod_settings_empty_description.current.fabricMACsec is defined |
| 223 |
- nm_update_pod_settings_empty_description.current.ntp is defined |
| 224 |
|
| 225 |
- name: Remove MACsec and NTP policies from Pod Settings |
| 226 |
cisco.mso.ndo_pod_settings: |
| 227 |
<<: *create_pod_settings |
| 228 |
macsec_policy: {} |
| 229 |
ntp_policy: {} |
| 230 |
register: nm_update_pod_settings_removed_policies |
| 231 |
|
| 232 |
- name: Assert Pod Settings update with removed policies |
| 233 |
ansible.builtin.assert: |
| 234 |
that: |
| 235 |
- nm_update_pod_settings_removed_policies is changed |
| 236 |
- nm_update_pod_settings_removed_policies.previous.name == 'ansible_pod_settings_1' |
| 237 |
- nm_update_pod_settings_removed_policies.previous.description == '' |
| 238 |
- nm_update_pod_settings_removed_policies.previous.fabricMACsecName == 'macsec_policy_2' |
| 239 |
- nm_update_pod_settings_removed_policies.previous.ntpName == 'ntp_policy_2' |
| 240 |
- nm_update_pod_settings_removed_policies.previous.uuid is defined |
| 241 |
- nm_update_pod_settings_removed_policies.previous.fabricMACsec is defined |
| 242 |
- nm_update_pod_settings_removed_policies.previous.ntp is defined |
| 243 |
- nm_update_pod_settings_removed_policies.proposed == nm_update_pod_settings_removed_policies.current |
| 244 |
- nm_update_pod_settings_removed_policies.current.description == '' |
| 245 |
- nm_update_pod_settings_removed_policies.current.fabricMACsecName is not defined |
| 246 |
- nm_update_pod_settings_removed_policies.current.ntpName is not defined |
| 247 |
- nm_update_pod_settings_removed_policies.current.uuid is defined |
| 248 |
- nm_update_pod_settings_removed_policies.current.fabricMACsec is not defined |
| 249 |
- nm_update_pod_settings_removed_policies.current.ntp is not defined |
| 250 |
|
| 251 |
- name: Create another Pod Settings |
| 252 |
cisco.mso.ndo_pod_settings: &create_pod_settings_2 |
| 253 |
<<: *create_pod_settings |
| 254 |
name: ansible_pod_settings_2 |
| 255 |
register: create_pod_settings_2 |
| 256 |
|
| 257 |
- name: Update name of Pod Settings |
| 258 |
cisco.mso.ndo_pod_settings: |
| 259 |
<<: *create_pod_settings_2 |
| 260 |
name: ansible_pod_settings_2_changed |
| 261 |
uuid: "{{create_pod_settings_2.current.uuid}}" |
| 262 |
register: update_pod_settings_name |
| 263 |
|
| 264 |
- name: Assert update of Pod Settings name |
| 265 |
ansible.builtin.assert: |
| 266 |
that: |
| 267 |
- update_pod_settings_name is changed |
| 268 |
- update_pod_settings_name.previous.name == 'ansible_pod_settings_2' |
| 269 |
- update_pod_settings_name.current.name == 'ansible_pod_settings_2_changed' |
| 270 |
- update_pod_settings_name.current.uuid == update_pod_settings_name.previous.uuid |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
- name: Query Pod Settings |
| 275 |
cisco.mso.ndo_pod_settings: |
| 276 |
<<: *create_pod_settings |
| 277 |
state: query |
| 278 |
register: query_pod_settings |
| 279 |
|
| 280 |
- name: Query all Pod Settings in Fabric Policy template |
| 281 |
cisco.mso.ndo_pod_settings: |
| 282 |
<<: *mso_info |
| 283 |
template: ansible_fabric_policy_template |
| 284 |
state: query |
| 285 |
register: query_all_pod_settings |
| 286 |
|
| 287 |
- name: Assert Pod Settings query |
| 288 |
ansible.builtin.assert: |
| 289 |
that: |
| 290 |
- query_pod_settings is not changed |
| 291 |
- query_pod_settings.current.name == 'ansible_pod_settings_1' |
| 292 |
- query_all_pod_settings is not changed |
| 293 |
- query_all_pod_settings.current | length == 2 |
| 294 |
- query_all_pod_settings.current[0].name == 'ansible_pod_settings_1' |
| 295 |
- query_all_pod_settings.current[1].name == 'ansible_pod_settings_2_changed' |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
- name: Pod Settings with mutually exclusive template parameters (error) |
| 300 |
cisco.mso.ndo_pod_settings: |
| 301 |
<<: *create_pod_settings |
| 302 |
template_id: template_id |
| 303 |
register: err_mutually_exclusive_template |
| 304 |
ignore_errors: true |
| 305 |
|
| 306 |
- name: Pod Settings with mutually exclusive macsec_policy parameters (error) |
| 307 |
cisco.mso.ndo_pod_settings: |
| 308 |
<<: *create_pod_settings |
| 309 |
macsec_policy: |
| 310 |
name: macsec_policy_1 |
| 311 |
macsec_policy_uuid: "{{ macsec_policies.results[1].current.uuid }}" |
| 312 |
register: err_mutually_exclusive_macsec_policy |
| 313 |
ignore_errors: true |
| 314 |
|
| 315 |
- name: Pod Settings with mutually exclusive ntp_policy parameters (error) |
| 316 |
cisco.mso.ndo_pod_settings: |
| 317 |
<<: *create_pod_settings |
| 318 |
ntp_policy: |
| 319 |
name: ntp_policy_1 |
| 320 |
ntp_policy_uuid: "{{ ntp_policies.results[1].current.uuid }}" |
| 321 |
register: err_mutually_exclusive_ntp_policy |
| 322 |
ignore_errors: true |
| 323 |
|
| 324 |
- name: Assert Pod Settings error handling |
| 325 |
ansible.builtin.assert: |
| 326 |
that: |
| 327 |
- err_mutually_exclusive_template is failed |
| 328 |
- 'err_mutually_exclusive_template.msg == "parameters are mutually exclusive: template|template_id"' |
| 329 |
- err_mutually_exclusive_macsec_policy is failed |
| 330 |
- 'err_mutually_exclusive_macsec_policy.msg == "parameters are mutually exclusive: macsec_policy|macsec_policy_uuid"' |
| 331 |
- err_mutually_exclusive_ntp_policy is failed |
| 332 |
- 'err_mutually_exclusive_ntp_policy.msg == "parameters are mutually exclusive: ntp_policy|ntp_policy_uuid"' |
| 333 |
|
| 334 |
- name: Pod Settings with invalid MACsec policy (error) |
| 335 |
cisco.mso.ndo_pod_settings: |
| 336 |
<<: *create_pod_settings |
| 337 |
macsec_policy: |
| 338 |
name: invalid_macsec_policy |
| 339 |
register: err_invalid_macsec_policy |
| 340 |
ignore_errors: true |
| 341 |
|
| 342 |
- name: Pod Settings with invalid NTP policy (error) |
| 343 |
cisco.mso.ndo_pod_settings: |
| 344 |
<<: *create_pod_settings |
| 345 |
ntp_policy: |
| 346 |
name: invalid_ntp_policy |
| 347 |
register: err_invalid_ntp_policy |
| 348 |
ignore_errors: true |
| 349 |
|
| 350 |
- name: Pod Settings with invalid MACsec policy UUID (error) |
| 351 |
cisco.mso.ndo_pod_settings: |
| 352 |
<<: *create_pod_settings |
| 353 |
macsec_policy_uuid: invalid_macsec_policy_uuid |
| 354 |
register: err_invalid_macsec_policy_uuid |
| 355 |
ignore_errors: true |
| 356 |
|
| 357 |
- name: Pod Settings with invalid NTP policy UUID (error) |
| 358 |
cisco.mso.ndo_pod_settings: |
| 359 |
<<: *create_pod_settings |
| 360 |
ntp_policy_uuid: invalid_ntp_policy_uuid |
| 361 |
register: err_invalid_ntp_policy_uuid |
| 362 |
ignore_errors: true |
| 363 |
|
| 364 |
- name: Set error messages for Pod Settings errors |
| 365 |
ansible.builtin.set_fact: |
| 366 |
error_message_invalid_macsec_policy: "Provided MACsec Policy with '[KVPair(key='name', value='invalid_macsec_policy')]' not matching existing object(s): macsec_policy_1, macsec_policy_2" |
| 367 |
error_message_invalid_ntp_policy: "Provided NTP Policy with '[KVPair(key='name', value='invalid_ntp_policy')]' not matching existing object(s): ntp_policy_1, ntp_policy_2" |
| 368 |
|
| 369 |
- name: Assert Pod Settings error handling |
| 370 |
ansible.builtin.assert: |
| 371 |
that: |
| 372 |
- err_invalid_macsec_policy is failed |
| 373 |
- err_invalid_macsec_policy.msg == error_message_invalid_macsec_policy |
| 374 |
- err_invalid_ntp_policy is failed |
| 375 |
- err_invalid_ntp_policy.msg == error_message_invalid_ntp_policy |
| 376 |
- err_invalid_macsec_policy_uuid is failed |
| 377 |
- err_invalid_macsec_policy_uuid.msg.startswith("Provided MACsec Policy with '[KVPair(key='uuid'") |
| 378 |
- err_invalid_ntp_policy_uuid is failed |
| 379 |
- err_invalid_ntp_policy_uuid.msg.startswith("Provided NTP Policy with '[KVPair(key='uuid'") |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
- name: Delete Pod Settings (check_mode) |
| 384 |
cisco.mso.ndo_pod_settings: &delete_pod_settings |
| 385 |
<<: *create_pod_settings |
| 386 |
state: absent |
| 387 |
register: cm_delete_pod_settings |
| 388 |
check_mode: true |
| 389 |
|
| 390 |
- name: Delete Pod Settings |
| 391 |
cisco.mso.ndo_pod_settings: |
| 392 |
<<: *delete_pod_settings |
| 393 |
register: nm_delete_pod_settings |
| 394 |
|
| 395 |
- name: Delete Pod Settings again |
| 396 |
cisco.mso.ndo_pod_settings: |
| 397 |
<<: *delete_pod_settings |
| 398 |
register: nm_delete_pod_settings_again |
| 399 |
|
| 400 |
- name: Assert Pod Settings deletion |
| 401 |
ansible.builtin.assert: |
| 402 |
that: |
| 403 |
- cm_delete_pod_settings is changed |
| 404 |
- cm_delete_pod_settings.previous.name == 'ansible_pod_settings_1' |
| 405 |
- cm_delete_pod_settings.proposed == {} |
| 406 |
- cm_delete_pod_settings.current == {} |
| 407 |
- nm_delete_pod_settings is changed |
| 408 |
- nm_delete_pod_settings.previous.name == 'ansible_pod_settings_1' |
| 409 |
- nm_delete_pod_settings.proposed == {} |
| 410 |
- nm_delete_pod_settings.current == {} |
| 411 |
- nm_delete_pod_settings_again is not changed |
| 412 |
- nm_delete_pod_settings_again.previous == nm_delete_pod_settings_again.current == nm_delete_pod_settings.current |
| 413 |
|
| 414 |
|
| 415 |
- name: Ensure Fabric Policy template does not exist |
| 416 |
cisco.mso.ndo_template: |
| 417 |
<<: *rm_fabric_policy_template |