---
#deployment tasks for redis

- name: Create a namespace for redis
  k8s:
    kubeconfig: "/etc/rancher/k3s/k3s.yaml"
    name: "{{apps.redis.namespace}}"
    api_version: v1
    kind: Namespace
    state: "{{apps.redis.state}}"
  become: true

#- name: create persistent volume resources
#  kubernetes.core.k8s:
#    kubeconfig: "/etc/rancher/k3s/k3s.yaml"
#    state: "{{apps.funkwhale.state}}"
#    definition: "{{ lookup('template', item) | from_yaml }}"
#  loop:
#    - funkwhale/pv.yaml
#    - funkwhale/pv-claim.yaml
#  become: true


- name: Install redis globally available
  block:
    - name: Add redis chart helm repo
      local_action:
        module: kubernetes.core.helm_repository
        name: bitnami
        repo_url: https://charts.bitnami.com/bitnami

    - name: load variables files/redis/values.yaml
      ansible.builtin.include_vars:
        file: files/redis/values.yaml
        name: release_values

    - name: Install redis Release
      local_action:
        module: kubernetes.core.helm
        release_state: "{{apps.redis.state}}"
        name: redis
        namespace: "{{apps.redis.namespace}}"
        create_namespace: yes
        update_repo_cache: True
        chart_ref: bitnami/redis
        values: "{{release_values}}"
        wait: true
