# 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: Git clone grafana plugin repo
  ansible.builtin.git:
    repo: "{{ grafana_plugins_github_repo }}"
    dest: "{{ mount_location + grafana_plugins_folder_name }}"
    version: main

- name: Wait for grafana pod to come to ready state
  command: kubectl wait --for=condition=ready --timeout=10m -n "{{ grafana_namespace }}" pod -l app="{{ grafana_k8s }}"
  changed_when: false
  
- name: Unzip plugins at grafana-plugins folder
  unarchive:
    src: "{{ mount_location + grafana_plugins_folder_name + item }}"
    dest: "{{ mount_location + grafana_k8s + '/plugins/'}}"
  with_items: "{{ plugins_name }}"
  changed_when: false

- name: Restart grafana deployment to add grafana plugins
  command: kubectl rollout restart deployment -n "{{ grafana_namespace }}"
  changed_when: false