# 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: Check existence of k8s on management station
  block:
    - name: Verify that kubernetes is installed
      command: kubectl cluster-info
      register: k8s_cluster_info
      failed_when: "'running' not in k8s_cluster_info.stdout"
      changed_when: false
      no_log: true
  rescue:
    - name: Kubernetes needs to be installed
      fail:
        msg: "{{ k8s_installation_required }}"

- name: Add kubernetes ansible-galaxy collection
  command: ansible-galaxy collection install kubernetes.core
  changed_when: false

- name: Check that the base_vars.yml exists
  stat:
    path: "{{ base_vars_file }}"
  register: stat_result

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

- name: Check that the login_vars.yml exists
  stat:
    path: "{{ login_vars_file }}"
  register: stat_result

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

- name: Install openshift using pip3
  pip:
    name: openshift
    state: present
    executable: pip3