# Test code for the MSO modules
# Copyright: (c) 2020, Lionel Hercot (@lhercot) <lhercot@cisco.com>

# GNU General Public License v3.0+ (see LICENSE 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: mso_hostname, mso_username and mso_password.'
  when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined


# CLEAN ENVIRONMENT
- name: Set vars
  set_fact:
    mso_info: &mso_info
      host: '{{ mso_hostname }}'
      username: '{{ mso_username }}'
      password: '{{ mso_password }}'
      validate_certs: '{{ mso_validate_certs | default(false) }}'
      use_ssl: '{{ mso_use_ssl | default(true) }}'
      use_proxy: '{{ mso_use_proxy | default(true) }}'
      output_level: '{{ mso_output_level | default("info") }}'

- name: Query MSO version
  mso_version:
    <<: *mso_info
    state: query
  register: version

- name: Set version vars
  set_fact:
    mso_rw: true
  when:
  - version.current.version[0] | int <= 2
  - version.current.version[:5] != '2.2.4'

- name: Import tasks if RW of role in this MSO version
  import_tasks: role-rw.yml
  when: mso_rw is defined

- name: Import tasks if RO of role in this MSO version
  import_tasks: role-ro.yml
  when: mso_rw is not defined