You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
5.8 KiB

  1. ---
  2. - hosts: all
  3. become: true
  4. gather_facts: no
  5. vars:
  6. docker_bin_dir: /usr/bin
  7. bin_dir: /usr/local/bin
  8. ansible_ssh_pipelining: true
  9. etcd_cert_dir: /etc/ssl/etcd/ssl
  10. kube_network_plugin: calico
  11. archive_dirname: collect-info
  12. commands:
  13. - name: timedate_info
  14. cmd: timedatectl status
  15. - name: kernel_info
  16. cmd: uname -r
  17. - name: docker_info
  18. cmd: "{{ docker_bin_dir }}/docker info"
  19. - name: ip_info
  20. cmd: ip -4 -o a
  21. - name: route_info
  22. cmd: ip ro
  23. - name: proc_info
  24. cmd: ps auxf | grep -v ]$
  25. - name: systemctl_failed_info
  26. cmd: systemctl --state=failed --no-pager
  27. - name: k8s_info
  28. cmd: "{{ bin_dir }}/kubectl get all --all-namespaces -o wide"
  29. - name: errors_info
  30. cmd: journalctl -p err --no-pager
  31. - name: etcd_info
  32. cmd: "{{ bin_dir }}/etcdctl --peers={{ etcd_access_addresses | default('http://127.0.0.1:2379') }} cluster-health"
  33. - name: calico_info
  34. cmd: "{{bin_dir}}/calicoctl node status"
  35. when: '{{ kube_network_plugin == "calico" }}'
  36. - name: calico_workload_info
  37. cmd: "{{bin_dir}}/calicoctl get workloadEndpoint -o wide"
  38. when: '{{ kube_network_plugin == "calico" }}'
  39. - name: calico_pool_info
  40. cmd: "{{bin_dir}}/calicoctl get ippool -o wide"
  41. when: '{{ kube_network_plugin == "calico" }}'
  42. - name: weave_info
  43. cmd: weave report
  44. when: '{{ kube_network_plugin == "weave" }}'
  45. - name: weave_logs
  46. cmd: "{{ docker_bin_dir }}/docker logs weave"
  47. when: '{{ kube_network_plugin == "weave" }}'
  48. - name: kube_describe_all
  49. cmd: "{{ bin_dir }}/kubectl describe all --all-namespaces"
  50. - name: kube_describe_nodes
  51. cmd: "{{ bin_dir }}/kubectl describe nodes"
  52. - name: kubelet_logs
  53. cmd: journalctl -u kubelet --no-pager
  54. - name: coredns_logs
  55. cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l k8s-app=coredns -o jsonpath={.items..metadata.name}`;
  56. do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
  57. - name: apiserver_logs
  58. cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l component=kube-apiserver -o jsonpath={.items..metadata.name}`;
  59. do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
  60. - name: controller_logs
  61. cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l component=kube-controller-manager -o jsonpath={.items..metadata.name}`;
  62. do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
  63. - name: scheduler_logs
  64. cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l component=kube-scheduler -o jsonpath={.items..metadata.name}`;
  65. do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
  66. - name: proxy_logs
  67. cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l k8s-app=kube-proxy -o jsonpath={.items..metadata.name}`;
  68. do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
  69. - name: nginx_logs
  70. cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l k8s-app=kube-nginx -o jsonpath={.items..metadata.name}`;
  71. do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
  72. - name: flannel_logs
  73. cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l app=flannel -o jsonpath={.items..metadata.name}`;
  74. do {{ bin_dir }}/kubectl logs ${i} -n kube-system flannel-container; done"
  75. when: '{{ kube_network_plugin == "flannel" }}'
  76. - name: canal_logs
  77. cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l k8s-app=canal-node -o jsonpath={.items..metadata.name}`;
  78. do {{ bin_dir }}/kubectl logs ${i} -n kube-system flannel; done"
  79. when: '{{ kube_network_plugin == "canal" }}'
  80. - name: calico_policy_logs
  81. cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l k8s-app=calico-kube-controllers -o jsonpath={.items..metadata.name}`;
  82. do {{ bin_dir }}/kubectl logs ${i} -n kube-system ; done"
  83. when: '{{ kube_network_plugin in ["canal", "calico"] }}'
  84. - name: helm_show_releases_history
  85. cmd: "for i in `{{ bin_dir }}/helm list -q`; do {{ bin_dir }}/helm history ${i} --col-width=0; done"
  86. when: "{{ helm_enabled|default(true) }}"
  87. logs:
  88. - /var/log/syslog
  89. - /var/log/daemon.log
  90. - /var/log/kern.log
  91. - /var/log/dpkg.log
  92. - /var/log/apt/history.log
  93. - /var/log/yum.log
  94. - /var/log/messages
  95. - /var/log/dmesg
  96. environment:
  97. ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}.pem"
  98. ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}-key.pem"
  99. tasks:
  100. - set_fact:
  101. etcd_access_addresses: |-
  102. {% for item in groups['etcd'] -%}
  103. https://{{ item }}:2379{% if not loop.last %},{% endif %}
  104. {%- endfor %}
  105. when: "'etcd' in groups"
  106. - name: Storing commands output
  107. shell: "{{ item.cmd }} 2>&1 | tee {{ item.name }}"
  108. failed_when: false
  109. with_items: "{{commands}}"
  110. when: item.when | default(True)
  111. no_log: True
  112. - name: Fetch results
  113. fetch: src={{ item.name }} dest=/tmp/{{ archive_dirname }}/commands
  114. with_items: "{{commands}}"
  115. when: item.when | default(True)
  116. failed_when: false
  117. - name: Fetch logs
  118. fetch: src={{ item }} dest=/tmp/{{ archive_dirname }}/logs
  119. with_items: "{{logs}}"
  120. failed_when: false
  121. - name: Pack results and logs
  122. archive:
  123. path: "/tmp/{{ archive_dirname }}"
  124. dest: "{{ dir|default('.') }}/logs.tar.gz"
  125. remove: true
  126. delegate_to: localhost
  127. become: false
  128. run_once: true
  129. - name: Clean up collected command outputs
  130. file: path={{ item.name }} state=absent
  131. with_items: "{{commands}}"