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.

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