| 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 |
|
| 12 |
|
| 13 |
- name: Set vars |
| 14 |
ansible.builtin.set_fact: |
| 15 |
mso_info: &mso_info |
| 16 |
host: '{{ mso_hostname }}' |
| 17 |
username: '{{ mso_username }}' |
| 18 |
password: '{{ mso_password }}' |
| 19 |
validate_certs: '{{ mso_validate_certs | default(false) }}' |
| 20 |
use_ssl: '{{ mso_use_ssl | default(true) }}' |
| 21 |
use_proxy: '{{ mso_use_proxy | default(true) }}' |
| 22 |
output_level: '{{ mso_output_level | default("debug") }}' |
| 23 |
aci_info: &aci_info |
| 24 |
host: "{{ apic_hostname }}" |
| 25 |
username: "{{ apic_username }}" |
| 26 |
password: "{{ apic_password }}" |
| 27 |
validate_certs: "{{ apic_validate_certs | default(false) }}" |
| 28 |
use_ssl: "{{ apic_use_ssl | default(true) }}" |
| 29 |
use_proxy: "{{ apic_use_proxy | default(true) }}" |
| 30 |
output_level: '{{ apic_output_level | default("debug") }}' |
| 31 |
|
| 32 |
- name: Query MSO version |
| 33 |
cisco.mso.mso_version: |
| 34 |
<<: *mso_info |
| 35 |
state: query |
| 36 |
register: version |
| 37 |
|
| 38 |
- name: Execute tasks only for MSO version < 5.0 |
| 39 |
when: version.current.version is version('5.0', '<') |
| 40 |
block: |
| 41 |
- name: Query all backups |
| 42 |
cisco.mso.mso_backup: |
| 43 |
<<: *mso_info |
| 44 |
state: query |
| 45 |
register: backups |
| 46 |
|
| 47 |
- name: Ensure all backups with link to remote location ansible_test are removed |
| 48 |
cisco.mso.mso_backup: |
| 49 |
<<: *mso_info |
| 50 |
backup_id: "{{ item.id }}" |
| 51 |
state: absent |
| 52 |
when: |
| 53 |
- item.location is defined |
| 54 |
- item.location.locationType is defined |
| 55 |
- item.location.locationType == "remote" |
| 56 |
loop: "{{ backups.current | sort(attribute='name', reverse=True) }}" |
| 57 |
|
| 58 |
- name: Ensure remote location ansible_test is removed |
| 59 |
cisco.mso.mso_remote_location: |
| 60 |
<<: *mso_info |
| 61 |
remote_location: ansible_test |
| 62 |
state: absent |
| 63 |
|
| 64 |
- name: Configure remote location scp (check mode) |
| 65 |
cisco.mso.mso_remote_location: &remote_location |
| 66 |
<<: *mso_info |
| 67 |
remote_location: ansible_test |
| 68 |
remote_protocol: scp |
| 69 |
remote_host: '{{ mso_remote_location }}' |
| 70 |
remote_path: '{{ mso_remote_location_path | default("/tmp") }}' |
| 71 |
authentication_type: password |
| 72 |
remote_username: '{{ mso_remote_location_user | default(mso_username) }}' |
| 73 |
remote_password: '{{ mso_remote_location_password | default(mso_password) }}' |
| 74 |
state: present |
| 75 |
check_mode: true |
| 76 |
register: cm_config_remote |
| 77 |
|
| 78 |
- name: Configure remote location scp |
| 79 |
cisco.mso.mso_remote_location: |
| 80 |
<<: *remote_location |
| 81 |
register: nm_config_remote |
| 82 |
|
| 83 |
- name: Verify configuration |
| 84 |
ansible.builtin.assert: |
| 85 |
that: |
| 86 |
- cm_config_remote is changed |
| 87 |
- cm_config_remote.current.name == "ansible_test" |
| 88 |
- cm_config_remote.current.credential.authType == "password" |
| 89 |
- cm_config_remote.current.credential.port == 22 |
| 90 |
- cm_config_remote.current.credential.protocolType == "scp" |
| 91 |
- cm_config_remote.current.credential.hostname == mso_remote_location |
| 92 |
- cm_config_remote.current.credential.remotePath == '/tmp' |
| 93 |
- cm_config_remote.current.credential.username == mso_remote_location_user|default(mso_username) |
| 94 |
- nm_config_remote is changed |
| 95 |
- nm_config_remote.current.name == "ansible_test" |
| 96 |
- nm_config_remote.current.credential.authType == "password" |
| 97 |
- nm_config_remote.current.credential.port == 22 |
| 98 |
- nm_config_remote.current.credential.protocolType == "scp" |
| 99 |
- nm_config_remote.current.credential.hostname == mso_remote_location |
| 100 |
- nm_config_remote.current.credential.remotePath == '/tmp' |
| 101 |
- nm_config_remote.current.credential.username == mso_remote_location_user|default(mso_username) |
| 102 |
- nm_config_remote.current.id is defined |
| 103 |
|
| 104 |
- name: Configure remote location again |
| 105 |
cisco.mso.mso_remote_location: |
| 106 |
<<: *remote_location |
| 107 |
register: nm_config_remote_again |
| 108 |
|
| 109 |
- name: Verify configuration after again |
| 110 |
ansible.builtin.assert: |
| 111 |
that: |
| 112 |
- nm_config_remote_again is not changed |
| 113 |
|
| 114 |
- name: Change remote location description (check mode) |
| 115 |
cisco.mso.mso_remote_location: |
| 116 |
<<: *remote_location |
| 117 |
description: changed_description |
| 118 |
check_mode: true |
| 119 |
register: cm_change_config_remote_description |
| 120 |
|
| 121 |
- name: Change remote location description |
| 122 |
cisco.mso.mso_remote_location: |
| 123 |
<<: *remote_location |
| 124 |
description: changed_description |
| 125 |
register: nm_change_config_remote_description |
| 126 |
|
| 127 |
- name: Verify configuration change |
| 128 |
ansible.builtin.assert: |
| 129 |
that: |
| 130 |
- cm_change_config_remote_description is changed |
| 131 |
- cm_change_config_remote_description.current.description == "changed_description" |
| 132 |
- nm_change_config_remote_description is changed |
| 133 |
- nm_change_config_remote_description.current.description == "changed_description" |
| 134 |
|
| 135 |
- name: Query remote location |
| 136 |
cisco.mso.mso_remote_location: |
| 137 |
<<: *remote_location |
| 138 |
state: query |
| 139 |
register: nm_query_remote |
| 140 |
|
| 141 |
- name: Query all remote locations |
| 142 |
cisco.mso.mso_remote_location: |
| 143 |
<<: *mso_info |
| 144 |
state: query |
| 145 |
register: nm_query_all_remotes |
| 146 |
|
| 147 |
- name: Query non existing remote location |
| 148 |
cisco.mso.mso_remote_location: |
| 149 |
<<: *mso_info |
| 150 |
remote_location: non_existing |
| 151 |
state: query |
| 152 |
ignore_errors: true |
| 153 |
register: nm_query_non_existing |
| 154 |
|
| 155 |
- name: Verify queries |
| 156 |
ansible.builtin.assert: |
| 157 |
that: |
| 158 |
- nm_query_remote is not changed |
| 159 |
- nm_query_remote.current | type_debug == "dict" |
| 160 |
- nm_query_all_remotes is not changed |
| 161 |
- nm_query_all_remotes.current | type_debug == "list" |
| 162 |
- nm_query_non_existing is not changed |
| 163 |
- 'nm_query_non_existing.msg == "Remote location non_existing not found. Remote locations configured: ansible_test"' |
| 164 |
|
| 165 |
- name: Remove remote location (check mode) |
| 166 |
cisco.mso.mso_remote_location: |
| 167 |
<<: *remote_location |
| 168 |
state: absent |
| 169 |
check_mode: true |
| 170 |
register: cm_delete_config_remote |
| 171 |
|
| 172 |
- name: Remove remote location |
| 173 |
cisco.mso.mso_remote_location: |
| 174 |
<<: *remote_location |
| 175 |
state: absent |
| 176 |
register: nm_delete_config_remote |
| 177 |
|
| 178 |
- name: Verify delete |
| 179 |
ansible.builtin.assert: |
| 180 |
that: |
| 181 |
- cm_delete_config_remote is changed |
| 182 |
- cm_delete_config_remote.current == {} |
| 183 |
- nm_delete_config_remote is changed |
| 184 |
- nm_delete_config_remote.current == {} |
| 185 |
|
| 186 |
- name: Create remote location different path directory if it does not exist |
| 187 |
ansible.builtin.file: |
| 188 |
path: '{{ mso_remote_location_alternate_path | default("/home/"~mso_username) }}' |
| 189 |
state: directory |
| 190 |
mode: '0755' |
| 191 |
|
| 192 |
- name: Configure remote location different path (check mode) |
| 193 |
cisco.mso.mso_remote_location: |
| 194 |
<<: *remote_location |
| 195 |
remote_path: '{{ mso_remote_location_alternate_path | default("/home/"~mso_username) }}' |
| 196 |
check_mode: true |
| 197 |
register: cm_config_remote_different_path |
| 198 |
|
| 199 |
- name: Configure remote location different path |
| 200 |
cisco.mso.mso_remote_location: |
| 201 |
<<: *remote_location |
| 202 |
remote_path: '{{ mso_remote_location_alternate_path | default("/home/"~mso_username) }}' |
| 203 |
register: nm_config_remote_different_path |
| 204 |
|
| 205 |
- name: Verify configuration different path |
| 206 |
ansible.builtin.assert: |
| 207 |
that: |
| 208 |
- cm_config_remote_different_path is changed |
| 209 |
- cm_config_remote_different_path.current.credential.remotePath == mso_remote_location_alternate_path|default("/home/"~mso_username) |
| 210 |
- nm_config_remote_different_path is changed |
| 211 |
- nm_config_remote_different_path.current.credential.remotePath == mso_remote_location_alternate_path|default("/home/"~mso_username) |
| 212 |
|
| 213 |
- name: Remove remote location |
| 214 |
cisco.mso.mso_remote_location: |
| 215 |
<<: *remote_location |
| 216 |
state: absent |
| 217 |
|
| 218 |
- name: Configure remote location sftp (check mode) |
| 219 |
cisco.mso.mso_remote_location: |
| 220 |
<<: *remote_location |
| 221 |
remote_protocol: sftp |
| 222 |
check_mode: true |
| 223 |
register: cm_config_remote_sftp |
| 224 |
|
| 225 |
- name: Configure remote location sftp |
| 226 |
cisco.mso.mso_remote_location: |
| 227 |
<<: *remote_location |
| 228 |
remote_protocol: sftp |
| 229 |
register: nm_config_remote_sftp |
| 230 |
|
| 231 |
- name: Verify configuration sftp |
| 232 |
ansible.builtin.assert: |
| 233 |
that: |
| 234 |
- cm_config_remote_sftp is changed |
| 235 |
- cm_config_remote_sftp.current.credential.protocolType == "sftp" |
| 236 |
- nm_config_remote_sftp is changed |
| 237 |
- nm_config_remote_sftp.current.credential.protocolType == "sftp" |
| 238 |
|
| 239 |
- name: Remove remote location |
| 240 |
cisco.mso.mso_remote_location: |
| 241 |
<<: *remote_location |
| 242 |
state: absent |
| 243 |
|
| 244 |
- name: Set ansible_network_os to cisco.aci.aci |
| 245 |
ansible.builtin.set_fact: |
| 246 |
ansible_network_os: cisco.aci.aci |
| 247 |
|
| 248 |
- name: Reset the ansible_connection to access the APIC |
| 249 |
ansible.builtin.meta: reset_connection |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
- name: Ensure SSH key exists on apic |
| 254 |
cisco.aci.aci_aaa_ssh_auth: |
| 255 |
<<: *aci_info |
| 256 |
aaa_user: '{{ mso_username }}' |
| 257 |
auth_name: ndo-rsa |
| 258 |
data: "{{ lookup('file', 'pki/rsa.pub') }}" |
| 259 |
state: present |
| 260 |
|
| 261 |
- name: Ensure SSH key exists on apic |
| 262 |
cisco.aci.aci_aaa_ssh_auth: |
| 263 |
<<: *aci_info |
| 264 |
aaa_user: '{{ mso_username }}' |
| 265 |
auth_name: ndo-rsa-pass |
| 266 |
data: "{{ lookup('file', 'pki/rsa-passphrase.pub') }}" |
| 267 |
state: present |
| 268 |
|
| 269 |
- name: Set ansible_network_os to cisco.nd.nd |
| 270 |
ansible.builtin.set_fact: |
| 271 |
ansible_network_os: cisco.nd.nd |
| 272 |
|
| 273 |
- name: Reset the ansible_connection to access the MSO/NDO |
| 274 |
ansible.builtin.meta: reset_connection |
| 275 |
|
| 276 |
- name: Configure remote location ssh (check mode) |
| 277 |
cisco.mso.mso_remote_location: &remote_location_ssh |
| 278 |
<<: *remote_location |
| 279 |
authentication_type: ssh |
| 280 |
remote_ssh_key: "{{ lookup('file', 'pki/rsa') }}" |
| 281 |
check_mode: true |
| 282 |
register: cm_config_remote_ssh |
| 283 |
|
| 284 |
- name: Configure remote location ssh |
| 285 |
cisco.mso.mso_remote_location: |
| 286 |
<<: *remote_location_ssh |
| 287 |
register: nm_config_remote_ssh |
| 288 |
|
| 289 |
- name: Verify configuration ssh |
| 290 |
ansible.builtin.assert: |
| 291 |
that: |
| 292 |
- cm_config_remote_ssh is changed |
| 293 |
- cm_config_remote_ssh.current.credential.authType == "sshKey" |
| 294 |
- nm_config_remote_ssh is changed |
| 295 |
- nm_config_remote_ssh.current.credential.authType == "sshKey" |
| 296 |
|
| 297 |
- name: Remove remote location |
| 298 |
cisco.mso.mso_remote_location: |
| 299 |
<<: *remote_location_ssh |
| 300 |
state: absent |
| 301 |
|
| 302 |
- name: Configure remote location ssh with passphrase (check mode) |
| 303 |
cisco.mso.mso_remote_location: &remote_location_ssh_pass |
| 304 |
<<: *remote_location |
| 305 |
authentication_type: ssh |
| 306 |
remote_ssh_key: "{{ lookup('file', 'pki/rsa-passphrase') }}" |
| 307 |
remote_ssh_passphrase: '{{ mso_ssh_passphrase | default("ansible") }}' |
| 308 |
check_mode: true |
| 309 |
register: cm_config_remote_ssh_pass |
| 310 |
|
| 311 |
- name: Configure remote location ssh with passphrase |
| 312 |
cisco.mso.mso_remote_location: |
| 313 |
<<: *remote_location_ssh_pass |
| 314 |
register: nm_config_remote_ssh_pass |
| 315 |
|
| 316 |
- name: Verify configuration ssh |
| 317 |
ansible.builtin.assert: |
| 318 |
that: |
| 319 |
- cm_config_remote_ssh_pass is changed |
| 320 |
- cm_config_remote_ssh_pass.current.credential.authType == "sshKey" |
| 321 |
- nm_config_remote_ssh_pass is changed |
| 322 |
- nm_config_remote_ssh_pass.current.credential.authType == "sshKey" |
| 323 |
|
| 324 |
- name: Remove remote location |
| 325 |
cisco.mso.mso_remote_location: |
| 326 |
<<: *remote_location_ssh_pass |
| 327 |
state: absent |