---
- name: CoreDNS | check if CoreDNS is cloned
  stat:
    path: "{{ kubernetes_dns.tmp_path }}/coredns-checkout"
  register: coredns_repo

- name: CoreDNS | git clone
  git:
    repo: "{{ kubernetes_dns.coredns_git_url }}"
    dest: "{{ kubernetes_dns.tmp_path }}/coredns-checkout"
    version: "{{ kubernetes_dns.branch }}"
  when: not coredns_repo.stat.exists

- name: CoreDNS | generate yaml and apply it
  shell: |
    set -o errexit
    cd {{ kubernetes_dns.tmp_path }}/coredns-checkout/kubernetes
    kubectl delete --namespace=kube-system deployment coredns --wait --ignore-not-found=true
    ./deploy.sh -i {{K8S_DNS_SERVICE_IP}} -d {{K8S_DNS_DOMAIN}} -s coredns.yaml.sed | kubectl apply --wait -f -
