- name: Cermanager | Create cloudns credentials
  environment:
    PATH: "{{ k8s_venv }}/bin:{{ ansible_env.PATH }}"
  vars:
    ansible_python_interpreter: "{{ k8s_venv }}/bin/python"
  kubernetes.core.k8s:
    state: present
    kubeconfig: "{{ k8s_kubeconfig }}"
    definition:
      apiVersion: v1
      kind: Secret
      metadata:
        name: cert-manager-webhook-cloudns-api-secret
        namespace: cert-manager
      type: Opaque
      data:
        auth_id: "{{ microk8s_cloudns_auth_id | b64encode }}"
        auth_password: "{{ microk8s_cloudns_auth_password | b64encode }}"

- name: CertManager | Copy clouDNS issuer manifest to Kubernetes cluster
  ansible.builtin.copy:
    src: "cert-manager/cloudns-issuer.yaml"
    dest: "{{ k8s_etc }}/k8s-certmanager-cloudns.yaml"
    mode: "0600"

- name: CertManager | Apply clouDNS issuer manifests
  environment:
    PATH: "{{ k8s_venv }}/bin:{{ ansible_env.PATH }}"
  vars:
    ansible_python_interpreter: "{{ k8s_venv }}/bin/python"
  kubernetes.core.k8s:
    state: present
    kubeconfig: "{{ k8s_kubeconfig }}"
    src: "{{ k8s_etc }}/k8s-certmanager-cloudns.yaml"
    wait: true
