| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
- name: Test that we have an ACI MultiSite host, username and password |
| 9 |
ansible.builtin.fail: |
| 10 |
msg: 'Please define the following variables: mso_hostname, mso_username and mso_password.' |
| 11 |
when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
- name: Set vars |
| 16 |
ansible.builtin.set_fact: |
| 17 |
mso_info: &mso_info |
| 18 |
host: '{{ mso_hostname }}' |
| 19 |
username: '{{ mso_username }}' |
| 20 |
password: '{{ mso_password }}' |
| 21 |
validate_certs: '{{ mso_validate_certs | default(false) }}' |
| 22 |
use_ssl: '{{ mso_use_ssl | default(true) }}' |
| 23 |
use_proxy: '{{ mso_use_proxy | default(true) }}' |
| 24 |
output_level: '{{ mso_output_level | default("debug") }}' |
| 25 |
|
| 26 |
- name: Query MSO version |
| 27 |
cisco.mso.mso_version: |
| 28 |
<<: *mso_info |
| 29 |
state: query |
| 30 |
register: version |
| 31 |
|
| 32 |
- name: Remove schemas |
| 33 |
cisco.mso.mso_schema: |
| 34 |
<<: *mso_info |
| 35 |
schema: '{{ item }}' |
| 36 |
state: absent |
| 37 |
loop: |
| 38 |
- '{{ mso_schema | default("ansible_test") }}_2' |
| 39 |
- '{{ mso_schema | default("ansible_test") }}' |
| 40 |
|
| 41 |
- name: Ensure site exists |
| 42 |
cisco.mso.mso_site: |
| 43 |
<<: *mso_info |
| 44 |
site: '{{ mso_site | default("ansible_test") }}' |
| 45 |
apic_username: '{{ apic_username }}' |
| 46 |
apic_password: '{{ apic_password }}' |
| 47 |
apic_site_id: '{{ apic_site_id }}' |
| 48 |
urls: |
| 49 |
- https://{{ apic_hostname }} |
| 50 |
state: present |
| 51 |
|
| 52 |
- name: Ensure tenant ansible_test exists to validate the invalid_site_mso_site |
| 53 |
cisco.mso.mso_tenant: |
| 54 |
<<: *mso_info |
| 55 |
tenant: ansible_test |
| 56 |
users: |
| 57 |
- '{{ mso_username }}' |
| 58 |
state: present |
| 59 |
|
| 60 |
- name: Dissociate sites that are associated with ansible_tenant |
| 61 |
cisco.mso.mso_tenant_site: |
| 62 |
<<: *mso_info |
| 63 |
tenant: ansible_test |
| 64 |
site: '{{ item }}' |
| 65 |
state: absent |
| 66 |
loop: |
| 67 |
- 'invalid_site_{{ mso_site | default("ansible_test") }}' |
| 68 |
- '{{ mso_site | default("ansible_test") }}' |
| 69 |
register: tenant_site_absent_check |
| 70 |
|
| 71 |
- name: Assertion check for the tenant site dissociation |
| 72 |
ansible.builtin.assert: |
| 73 |
that: |
| 74 |
- tenant_site_absent_check.results.0.current == {} |
| 75 |
- tenant_site_absent_check.warnings.0 == "Site 'invalid_site_ansible_test' is not a valid site name." |
| 76 |
- tenant_site_absent_check.results.1.current == {} |
| 77 |
|
| 78 |
- name: Associate site with ansible_test in check mode |
| 79 |
cisco.mso.mso_tenant_site: |
| 80 |
<<: *mso_info |
| 81 |
tenant: ansible_test |
| 82 |
site: '{{ mso_site | default("ansible_test") }}' |
| 83 |
state: present |
| 84 |
check_mode: true |
| 85 |
register: ncs_cm |
| 86 |
|
| 87 |
- name: Verify ncs_cm |
| 88 |
ansible.builtin.assert: |
| 89 |
that: |
| 90 |
- ncs_cm is changed |
| 91 |
|
| 92 |
- name: Associate site with ansible_test in normal mode |
| 93 |
cisco.mso.mso_tenant_site: |
| 94 |
<<: *mso_info |
| 95 |
tenant: ansible_test |
| 96 |
site: '{{ mso_site | default("ansible_test") }}' |
| 97 |
state: present |
| 98 |
register: ncs_nm |
| 99 |
|
| 100 |
- name: Verify ncs_nm |
| 101 |
ansible.builtin.assert: |
| 102 |
that: |
| 103 |
- ncs_nm is changed |
| 104 |
|
| 105 |
- name: Associate site with ansible_test again in normal mode |
| 106 |
cisco.mso.mso_tenant_site: |
| 107 |
<<: *mso_info |
| 108 |
tenant: ansible_test |
| 109 |
site: '{{ mso_site | default("ansible_test") }}' |
| 110 |
state: present |
| 111 |
register: ncs_nm_again |
| 112 |
|
| 113 |
- name: Verify ncs_nm_again |
| 114 |
ansible.builtin.assert: |
| 115 |
that: |
| 116 |
- ncs_nm_again is not changed |
| 117 |
|
| 118 |
- name: Query associated site of a tenant |
| 119 |
cisco.mso.mso_tenant_site: |
| 120 |
<<: *mso_info |
| 121 |
tenant: ansible_test |
| 122 |
site: '{{ mso_site | default("ansible_test") }}' |
| 123 |
state: query |
| 124 |
register: anc_query |
| 125 |
|
| 126 |
- name: Verify anc_query |
| 127 |
ansible.builtin.assert: |
| 128 |
that: |
| 129 |
- anc_query is not changed |
| 130 |
|
| 131 |
- name: Query all associated sites of a tenant |
| 132 |
cisco.mso.mso_tenant_site: |
| 133 |
<<: *mso_info |
| 134 |
tenant: ansible_test |
| 135 |
state: query |
| 136 |
register: all_sites_query |
| 137 |
|
| 138 |
- name: Verify all_sites_query |
| 139 |
ansible.builtin.assert: |
| 140 |
that: |
| 141 |
- all_sites_query is not changed |
| 142 |
|
| 143 |
- name: Dissociate site with ansible_test |
| 144 |
cisco.mso.mso_tenant_site: |
| 145 |
<<: *mso_info |
| 146 |
tenant: ansible_test |
| 147 |
site: '{{ mso_site | default("ansible_test") }}' |
| 148 |
state: absent |
| 149 |
register: dnc |
| 150 |
|
| 151 |
- name: Verify dnc |
| 152 |
ansible.builtin.assert: |
| 153 |
that: |
| 154 |
- dnc is changed |
| 155 |
|
| 156 |
- name: Query dissociated site of a tenant |
| 157 |
cisco.mso.mso_tenant_site: |
| 158 |
<<: *mso_info |
| 159 |
tenant: ansible_test |
| 160 |
site: '{{ mso_site | default("ansible_test") }}' |
| 161 |
state: query |
| 162 |
ignore_errors: true |
| 163 |
register: dnc_query |
| 164 |
|
| 165 |
- name: Verify dnc_query for MSO version >= 3.7 |
| 166 |
ansible.builtin.assert: |
| 167 |
that: |
| 168 |
- dnc_query.msg is match ("No site associated with tenant Id [0-9a-zA-Z]*") |
| 169 |
when: version.current.version is version('3.7', '>=') |
| 170 |
|
| 171 |
- name: Verify dnc_query MSO version <= 3.7 |
| 172 |
ansible.builtin.assert: |
| 173 |
that: |
| 174 |
- dnc_query.msg is match ("Site Id [0-9a-zA-Z]* not associated with tenant Id [0-9a-zA-Z]*") |
| 175 |
when: version.current.version is version('3.7', '<=') |
| 176 |
|
| 177 |
- name: Query all |
| 178 |
cisco.mso.mso_tenant_site: |
| 179 |
<<: *mso_info |
| 180 |
tenant: ansible_test |
| 181 |
state: query |
| 182 |
ignore_errors: true |
| 183 |
register: query_all |
| 184 |
|
| 185 |
- name: Verify query_all |
| 186 |
ansible.builtin.assert: |
| 187 |
that: |
| 188 |
- query_all.msg is match ("No site associated with tenant Id [0-9a-zA-Z]*") |