# 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 awx and grafana on management station
  block:
    - name: Check AWX instance
      command: awx --version
      changed_when: false

    - name: Check grafana service
      command: kubectl get svc -n grafana
      register: grafana_svc_register
      failed_when: "'grafana' not in grafana_svc_register.stdout"
      changed_when: false
  rescue:
    - name: AWX and grafana needs to be installed
      fail:
        msg: "{{ control_plane_installation_required }}"

- 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 telemetry/login_vars.yml exists
  stat:
    path: "{{ login_vars_file }}"
  register: stat_result

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

- name: Check that control_plane/login_vars.yml exists
  stat:
    path: "{{ ctrl_plane_login_vars_filename }}"
  register: stat_result

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

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