# Copyright 2022 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: Include control_plane_common vars
  include_vars: ../../control_plane_common/vars/main.yml  

- name: Include provision_cobbler vars
  include_vars: ../../provision_cobbler/vars/main.yml

- name: Install xorriso package - rocky
  package:
    name: "{{ iso_package }}"
    state: present
  when: os_supported_leap not in mgmt_os

- name: Install xorriso package - leap
  zypper:
    name: "{{ iso_package }}"
    state: present
  when: os_supported_leap in mgmt_os

- name: Install ansible-galaxy modules
  command: ansible-galaxy collection install {{ item }}
  changed_when: true
  with_items: "{{ idrac_collections }}"

- name: Install omsdk using pip
  pip:
    name: omsdk
    state: present

- name: Check iso mount folder
  stat:
    path: "{{ iso_mount_path }}{{ grub_cfg_path }}"
  register: check_mount_iso

- name: Include provision_cobbler vars
  include_tasks: ../../provision_cobbler/tasks/mount_iso.yml
  when: not check_mount_iso.stat.exists

- name: Recheck iso mount folder
  stat:
    path: "{{ iso_mount_path }}{{ grub_cfg_path }}"
  register: recheck_mount_iso
  when: not check_mount_iso.stat.exists

- name: Incorrect iso mount
  fail:
    msg: "{{ iso_mount_check_fail_msg }}"
  when:
    - not check_mount_iso.stat.exists
    - not recheck_mount_iso.stat.exists
  register: iso_mount_fail 

- name: Copy management station ip to {{ management_station_ip_file }}
  lineinfile:
    path: "{{ role_path }}/../provision_idrac/files/{{ management_station_ip_file }}"
    line: "{{ mngmnt_network_ip }}"
    mode: "{{ file_permission }}"
    create: yes
  when: device_config_support

- name: Copy management station ip to {{ management_station_ip_file }}
  lineinfile:
    path: "{{ role_path }}/../provision_idrac/files/{{ management_station_ip_file }}"
    line: "{{ public_ip }}"
    mode: "{{ file_permission }}"
    create: yes
  when: not device_config_support