---
- name: Custom CNI | Manifest deployment
  when: not custom_cni_chart_release_name | length > 0
  block:
  - name: Custom CNI | Check Custom CNI Manifests
    assert:
      that:
      - "custom_cni_manifests | length > 0"
      msg: "custom_cni_manifests should not be empty"

  - name: Custom CNI | Copy Custom manifests
    template:
      src: "{{ item }}"
      dest: "{{ kube_config_dir }}/{{ item | basename | replace('.j2', '') }}"
      mode: 0644
    loop: "{{ custom_cni_manifests }}"
    delegate_to: "{{ groups['kube_control_plane'] | first }}"
    run_once: true

  - name: Custom CNI | Start Resources
    kube:
      namespace: "kube-system"
      kubectl: "{{ bin_dir }}/kubectl"
      filename: "{{ kube_config_dir }}/{{ item | basename | replace('.j2', '') }}"
      state: "latest"
      wait: true
    loop: "{{ custom_cni_manifests }}"
    delegate_to: "{{ groups['kube_control_plane'] | first }}"
    run_once: true
