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.

118 lines
4.7 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. system_namespace: kube-system
  9. ansible_ssh_pipelining: true
  10. commands:
  11. - name: timedate_info
  12. cmd: timedatectl status
  13. - name: kernel_info
  14. cmd: uname -r
  15. - name: docker_info
  16. cmd: "{{ docker_bin_dir }}/docker info"
  17. - name: ip_info
  18. cmd: ip -4 -o a
  19. - name: route_info
  20. cmd: ip ro
  21. - name: proc_info
  22. cmd: ps auxf | grep -v ]$
  23. - name: systemctl_failed_info
  24. cmd: systemctl --state=failed --no-pager
  25. - name: k8s_info
  26. cmd: kubectl get all --all-namespaces -o wide
  27. - name: errors_info
  28. cmd: journalctl -p err --no-pager
  29. - name: etcd_info
  30. cmd: etcdctl --peers={{ etcd_access_addresses | default("http://127.0.0.1:2379") }} cluster-health
  31. - name: calico_info
  32. cmd: "{{bin_dir}}/calicoctl node status"
  33. - name: calico_workload_info
  34. cmd: "{{bin_dir}}/calicoctl get workloadEndpoint -o wide"
  35. - name: calico_pool_info
  36. cmd: "{{bin_dir}}/calicoctl get ippool -o wide"
  37. - name: weave_info
  38. cmd: weave report
  39. - name: weave_logs
  40. cmd: "{{ docker_bin_dir }}/docker logs weave"
  41. - name: kube_describe_all
  42. cmd: kubectl describe all --all-namespaces
  43. - name: kube_describe_nodes
  44. cmd: kubectl describe nodes
  45. - name: kubelet_logs
  46. cmd: journalctl -u kubelet --no-pager
  47. - name: kubedns_logs
  48. cmd: "for i in `kubectl get pods --all-namespaces -l k8s-app=kubedns -o jsonpath={.items..metadata.name}`;
  49. do kubectl logs ${i} --namespace {{system_namespace}} kubedns; done"
  50. - name: apiserver_logs
  51. cmd: "for i in `kubectl get pods --all-namespaces -l k8s-app=kube-apiserver -o jsonpath={.items..metadata.name}`;
  52. do kubectl logs ${i} --namespace {{system_namespace}}; done"
  53. - name: controller_logs
  54. cmd: "for i in `kubectl get pods --all-namespaces -l k8s-app=kube-controller -o jsonpath={.items..metadata.name}`;
  55. do kubectl logs ${i} --namespace {{system_namespace}}; done"
  56. - name: scheduler_logs
  57. cmd: "for i in `kubectl get pods --all-namespaces -l k8s-app=kube-scheduler -o jsonpath={.items..metadata.name}`;
  58. do kubectl logs ${i} --namespace {{system_namespace}}; done"
  59. - name: proxy_logs
  60. cmd: "for i in `kubectl get pods --all-namespaces -l k8s-app=kube-proxy -o jsonpath={.items..metadata.name}`;
  61. do kubectl logs ${i} --namespace {{system_namespace}}; done"
  62. - name: nginx_logs
  63. cmd: "for i in `kubectl get pods --all-namespaces -l k8s-app=kube-nginx -o jsonpath={.items..metadata.name}`;
  64. do kubectl logs ${i} --namespace {{system_namespace}}; done"
  65. - name: flannel_logs
  66. cmd: "for i in `kubectl get pods --all-namespaces -l app=flannel -o jsonpath={.items..metadata.name}`;
  67. do kubectl logs ${i} --namespace {{system_namespace}} flannel-container; done"
  68. - name: canal_logs
  69. cmd: "for i in `kubectl get pods --all-namespaces -l k8s-app=canal-node -o jsonpath={.items..metadata.name}`;
  70. do kubectl logs ${i} --namespace {{system_namespace}} flannel; done"
  71. - name: calico_policy_logs
  72. cmd: "for i in `kubectl get pods --all-namespaces -l k8s-app=calico-policy -o jsonpath={.items..metadata.name}`;
  73. do kubectl logs ${i} --namespace {{system_namespace}} calico-policy-controller; done"
  74. logs:
  75. - /var/log/syslog
  76. - /var/log/daemon.log
  77. - /var/log/kern.log
  78. - /var/log/dpkg.log
  79. - /var/log/apt/history.log
  80. - /var/log/yum.log
  81. - /var/log/calico/bird/current
  82. - /var/log/calico/bird6/current
  83. - /var/log/calico/felix/current
  84. - /var/log/calico/confd/current
  85. tasks:
  86. - set_fact:
  87. etcd_access_addresses: |-
  88. {% for item in groups['etcd'] -%}
  89. https://{{ item }}:2379{% if not loop.last %},{% endif %}
  90. {%- endfor %}
  91. when: "'etcd' in groups"
  92. - name: Storing commands output
  93. shell: "{{ item.cmd }} 2>&1 | tee {{ item.name }}"
  94. failed_when: false
  95. with_items: "{{commands}}"
  96. no_log: True
  97. - name: Fetch results
  98. fetch: src={{ item.name }} dest=/tmp/collect-info/commands
  99. with_items: "{{commands}}"
  100. failed_when: false
  101. - name: Fetch logs
  102. fetch: src={{ item }} dest=/tmp/collect-info/logs
  103. with_items: "{{logs}}"
  104. - name: Pack results and logs
  105. local_action: raw GZIP=-9 tar --remove-files -cvzf {{dir|default(".")}}/logs.tar.gz -C /tmp collect-info
  106. run_once: true
  107. - name: Clean up collected command outputs
  108. file: path={{ item.name }} state=absent
  109. with_items: "{{commands}}"