---
- name: Ensure k3s config directory exists
  file:
    path: /etc/rancher/k3s
    state: directory
    mode: "0755"
  when: k3s_registry_mirror_enabled | bool

- name: Configure k3s registry mirrors
  template:
    src: registries.yaml.j2
    dest: /etc/rancher/k3s/registries.yaml
    mode: "0644"
  when: k3s_registry_mirror_enabled | bool

- name: Remove k3s registry mirror config when disabled
  file:
    path: /etc/rancher/k3s/registries.yaml
    state: absent
  when: not (k3s_registry_mirror_enabled | bool)
