---
# https://cert-manager.io/docs/installation/helm/#installing-with-helm
- name: install cert-manager
  kubernetes.core.helm:
    kubeconfig_path: "/etc/rancher/k3s/k3s.yaml"
    atomic: true
    name: cert-manager
    chart_ref: oci://quay.io/jetstack/charts/cert-manager
    chart_version: "v1.18.2"
    release_namespace: cert-manager
    create_namespace: true
    release_values:
      installCRDs: true
  become: true

# create issuer
- name: create let's encrypt issuers
  kubernetes.core.k8s:
    kubeconfig: "/etc/rancher/k3s/k3s.yaml"
    state: present
    definition: "{{ lookup('file', item) | from_yaml }}"
  become: true
  loop:
    - 'cert-manager/acme.issuer.stg.yaml'
    - 'cert-manager/acme.issuer.prod.yaml'

- name: create let's encrypt certificates
  kubernetes.core.k8s:
    kubeconfig: "/etc/rancher/k3s/k3s.yaml"
    state: present
    definition: "{{ lookup('file', item) | from_yaml }}"
  become: true
  loop:
    - 'cert-manager/certificate.xai-corp.stg.yaml'
    - 'cert-manager/certificate.xai-corp.prod.yaml'
