# Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---

- name: Install paramiko
  command: pip3 install paramiko -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
  delegate_to: localhost
  changed_when: false

- name: Check if ethernet_tor_vars.yml exists
  stat:
    path: "{{ tor_config_file }}"
  register: stat_result

- name: Fail if config file doesn't exist
  fail:
    msg: "{{ fail_msg_tor_config_file }}"
  when: not stat_result.stat.exists

- name: Check if ethernet_vars.yml exists
  stat:
    path: "{{ config_file }}"
  register: stat_result

- name: Fail if config file doesn't exist
  fail:
    msg: "{{ fail_msg_config_file }}"
  when: not stat_result.stat.exists

- name: Check switch model name
  dellos10_command:
    commands: 'show system | grep "Current Type"'
  register: model_type

- name: Save switch model name
  set_fact:
    model_type: "{{ model_type.stdout[0].split(' ')[-1] }}"

- name: Pre-requisite tasks for S3* and S4* switches
  block:
    - name: Include ethernet_tor_vars.yml config variable file
      include_vars: "{{ tor_config_file }}"

    - name: Assert save_changes_to_startup variable
      assert:
        that: "save_changes_to_startup == true or save_changes_to_startup == false"
        success_msg: "{{ success_msg_tor_save_config }}"
        fail_msg: "{{ fail_msg_tor_save_config }}"

  when: "'S3' in model_type or 'S4' in model_type"

- name: Pre-requisite tasks for other ethernet switches
  block:
    - name: Include ethernet_vars.yml config variable file
      include_vars: "{{ config_file }}"

    - name: Assert save_changes_to_startup variable
      assert:
        that: "save_changes_to_startup == true or save_changes_to_startup == false"
        success_msg: "{{ success_msg_save_config }}"
        fail_msg: "{{ fail_msg_save_config }}"

  when: "'S3' not in model_type and 'S4' not in model_type"