ansible/test/integration/targets/msc_site/tasks/main.yml

277 lines
7.1 KiB
YAML
Raw Normal View History

# Test code for the MSC modules
# Copyright: (c) 2018, Dag Wieers (@dagwieers) <dag@wieers.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Test that we have an ACI MultiSite host, username and password
fail:
msg: 'Please define the following variables: msc_hostname, msc_username and msc_password.'
when: msc_hostname is not defined or msc_username is not defined or msc_password is not defined
# CLEAN ENVIRONMENT
- name: Remove site ansible_test2
msc_site: &site_absent
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
site: ansible_test2
state: absent
- name: Remove site ansible_test
msc_site:
<<: *site_absent
site: ansible_test
register: cm_remove_site
# ADD SITE
- name: Add site (check_mode)
msc_site: &site_present
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
site: ansible_test
apic_username: admin
apic_password: '{{ apic_password }}'
apic_site_id: 101
urls:
- https://{{ apic_hostname }}/
state: present
check_mode: yes
register: cm_add_site
- name: Verify cm_add_site
assert:
that:
- cm_add_site is changed
- cm_add_site.previous == {}
- cm_add_site.current.id is not defined
- cm_add_site.current.name == 'ansible_test'
- name: Add site (normal mode)
msc_site: *site_present
register: nm_add_site
- name: nm_Verify add_site
assert:
that:
- nm_add_site is changed
- nm_add_site.previous == {}
- nm_add_site.current.id is defined
- nm_add_site.current.name == 'ansible_test'
- name: Add site again (check_mode)
msc_site: *site_present
check_mode: yes
register: cm_add_site_again
- name: Verify cm_add_site_again
assert:
that:
- cm_add_site_again is not changed
- cm_add_site_again.previous.name == 'ansible_test'
- cm_add_site_again.current.id == nm_add_site.current.id
- cm_add_site_again.current.name == 'ansible_test'
- name: Add site again (normal mode)
msc_site: *site_present
register: nm_add_site_again
- name: Verify nm_add_site_again
assert:
that:
- nm_add_site_again is not changed
- nm_add_site_again.previous.name == 'ansible_test'
- nm_add_site_again.current.id == nm_add_site.current.id
- nm_add_site_again.current.name == 'ansible_test'
# CHANGE SITE
- name: Change site (check_mode)
msc_site:
<<: *site_present
site_id: '{{ nm_add_site.current.id }}'
site: ansible_test2
check_mode: yes
register: cm_change_site
- name: Verify cm_change_site
assert:
that:
- cm_change_site is changed
- cm_change_site.current.id == nm_add_site.current.id
- cm_change_site.current.name == 'ansible_test2'
- name: Change site (normal mode)
msc_site:
<<: *site_present
site_id: '{{ nm_add_site.current.id }}'
site: ansible_test2
output_level: debug
register: nm_change_site
- name: Verify nm_change_site
assert:
that:
- nm_change_site is changed
- nm_change_site.current.id == nm_add_site.current.id
- nm_change_site.current.name == 'ansible_test2'
- name: Change site again (check_mode)
msc_site:
<<: *site_present
site_id: '{{ nm_add_site.current.id }}'
site: ansible_test2
check_mode: yes
register: cm_change_site_again
- name: Verify cm_change_site_again
assert:
that:
- cm_change_site_again is not changed
- cm_change_site_again.current.id == nm_add_site.current.id
- cm_change_site_again.current.name == 'ansible_test2'
- name: Change site again (normal mode)
msc_site:
<<: *site_present
site_id: '{{ nm_add_site.current.id }}'
site: ansible_test2
register: nm_change_site_again
- name: Verify nm_change_site_again
assert:
that:
- nm_change_site_again is not changed
- nm_change_site_again.current.id == nm_add_site.current.id
- nm_change_site_again.current.name == 'ansible_test2'
# QUERY ALL SITES
- name: Query all sites (check_mode)
msc_site: &site_query
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
state: query
check_mode: yes
register: cm_query_all_sites
- name: Query all sites (normal mode)
msc_site: *site_query
register: nm_query_all_sites
- name: Verify query_all_sites
assert:
that:
- cm_query_all_sites is not changed
- nm_query_all_sites is not changed
# NOTE: Order of sites is not stable between calls
#- cm_query_all_sites == nm_query_all_sites
# QUERY A SITE
- name: Query our site
msc_site:
<<: *site_query
site: ansible_test2
check_mode: yes
register: cm_query_site
- name: Query our site
msc_site:
<<: *site_query
site: ansible_test2
register: nm_query_site
- name: Verify query_site
assert:
that:
- cm_query_site is not changed
- cm_query_site.current.id == nm_add_site.current.id
- cm_query_site.current.name == 'ansible_test2'
- nm_query_site is not changed
- nm_query_site.current.id == nm_add_site.current.id
- nm_query_site.current.name == 'ansible_test2'
- cm_query_site == nm_query_site
# REMOVE SITE
- name: Remove site (check_mode)
msc_site: *site_absent
check_mode: yes
register: cm_remove_site
- name: Verify cm_remove_site
assert:
that:
- cm_remove_site is changed
- cm_remove_site.current == {}
- name: Remove site (normal mode)
msc_site: *site_absent
register: nm_remove_site
- name: Verify nm_remove_site
assert:
that:
- nm_remove_site is changed
- nm_remove_site.current == {}
- name: Remove site again (check_mode)
msc_site: *site_absent
check_mode: yes
register: cm_remove_site_again
- name: Verify cm_remove_site_again
assert:
that:
- cm_remove_site_again is not changed
- cm_remove_site_again.current == {}
- name: Remove site again (normal mode)
msc_site: *site_absent
register: nm_remove_site_again
- name: Verify nm_remove_site_again
assert:
that:
- nm_remove_site_again is not changed
- nm_remove_site_again.current == {}
# QUERY NON-EXISTING SITE
- name: Query non-existing site (check_mode)
msc_site:
<<: *site_query
site: ansible_test
check_mode: yes
register: cm_query_non_site
- name: Query non-existing site (normal mode)
msc_site:
<<: *site_query
site: ansible_test
register: nm_query_non_site
# TODO: Implement more tests
- name: Verify query_non_site
assert:
that:
- cm_query_non_site is not changed
- nm_query_non_site is not changed
- cm_query_non_site == nm_query_non_site