# 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.
---

# pre-req

- name: Create directories if they don't exist
  block:
    - name: Checking directory
      stat:
        path: "{{ item }}"
      register: stat_result
      with_items:
        - "{{ subnet_manager.cache_directory }}"
        - "{{ subnet_manager.log_directory }}"
      loop_control:
        label: "{{ item }}"
      tags: install

    - name: Creating directories
      file:
        path: "{{ item.item }}"
        state: directory
        mode: "{{ folder_perm }}"
        group: root
        owner: root
      when: not item.stat.exists
      loop: "{{ stat_result.results }}"
      loop_control:
        label: "{{ item.item }}"
      tags: install

- name: Copy opensm configuration file
  copy:
    src: "{{ opensm_conf_file }}"
    dest: "{{ opensm_conf_file_dest }}"
    force: yes
  tags: install