github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/ansible/roles/coredns/tasks/main.yaml (about) 1 --- 2 - name: create /etc/kubernetes/specs directory 3 file: 4 path: "{{ kubernetes_spec_dir }}" 5 state: directory 6 - name: copy coredns.yaml to remote 7 template: 8 src: coredns.yaml 9 dest: "{{ kubernetes_spec_dir }}/coredns.yaml" 10 - name: start coredns service 11 command: kubectl --kubeconfig {{ kubernetes_kubeconfig.kubectl }} apply -f {{ kubernetes_spec_dir }}/coredns.yaml 12 register: out 13 14 - block: 15 - name: wait up to 5 minutes until DNS pods are ready 16 command: kubectl --kubeconfig {{ kubernetes_kubeconfig.kubectl }} get deployment coredns -n kube-system -o jsonpath='{.status.availableReplicas}' 17 register: readyReplicas 18 until: readyReplicas.stdout|int == dns.options.replicas|int 19 retries: 30 20 delay: 10 21 failed_when: false # We don't want this task to actually fail (We catch the failure with a custom msg in the next task) 22 23 - name: find the DNS pods that failed to start 24 # Get the name and status/phase for all coredns pods, and then filter out the ones that are not running. 25 # Once we have those, grab the first one, and cut the status/phase out of the output. 26 raw: > 27 kubectl get pods -n kube-system -l k8s-app=coredns 28 --no-headers -o custom-columns=name:{.metadata.name},status:{.status.phase} | grep -v "Running" | head -n 1 | cut -d " " -f 1 29 register: failedDNSPodNames 30 when: readyReplicas.stdout|int != dns.options.replicas|int 31 32 - name: get the logs of the first DNS pod that did not start up in time 33 command: kubectl --kubeconfig {{ kubernetes_kubeconfig.kubectl }} logs -n kube-system {{ failedDNSPodNames.stdout_lines[0] }} --tail 15 34 register: failedDNSPodLogs 35 when: "'stdout_lines' in failedDNSPodNames and failedDNSPodNames.stdout_lines|length > 0" 36 37 - name: fail if DNS pods are not ready 38 fail: 39 msg: | 40 Waited for all DNS pods to be ready, but they took longer than 5 minutes to be in the ready state. 41 42 The pod's latest logs may indicate why it failed to start up: 43 44 {{ failedDNSPodLogs.stdout }} 45 46 when: readyReplicas.stdout|int != dns.options.replicas|int 47 when: run_pod_validation|bool == true