---
# deployment tasks for MetalLB
# https://metallb.io/installation/

#- name: Create a namespace for funkwhale
#  k8s:
#    kubeconfig: "/etc/rancher/k3s/k3s.yaml"
#    name: "{{apps.funkwhale.namespace}}"
#    api_version: v1
#    kind: Namespace
#    state: "{{apps.funkwhale.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 MetalLB chart
  block:
    - name: Add MetaLB chart helm repo
      local_action:
        module: kubernetes.core.helm_repository
        name: metallb
        repo_url: https://metallb.github.io/metallb

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

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