2016-08-08 19:38:25 +08:00
|
|
|
---
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Collect debug info
|
|
|
|
hosts: all
|
2016-11-21 18:20:44 +08:00
|
|
|
become: true
|
2016-08-08 19:38:25 +08:00
|
|
|
gather_facts: no
|
|
|
|
|
|
|
|
vars:
|
2017-04-10 23:49:17 +08:00
|
|
|
docker_bin_dir: /usr/bin
|
|
|
|
bin_dir: /usr/local/bin
|
|
|
|
ansible_ssh_pipelining: true
|
2017-11-07 22:06:16 +08:00
|
|
|
etcd_cert_dir: /etc/ssl/etcd/ssl
|
2019-02-05 04:46:48 +08:00
|
|
|
kube_network_plugin: calico
|
|
|
|
archive_dirname: collect-info
|
2016-08-08 19:38:25 +08:00
|
|
|
commands:
|
|
|
|
- name: timedate_info
|
|
|
|
cmd: timedatectl status
|
|
|
|
- name: kernel_info
|
|
|
|
cmd: uname -r
|
|
|
|
- name: docker_info
|
2016-12-23 22:44:44 +08:00
|
|
|
cmd: "{{ docker_bin_dir }}/docker info"
|
2016-08-08 19:38:25 +08:00
|
|
|
- name: ip_info
|
|
|
|
cmd: ip -4 -o a
|
|
|
|
- name: route_info
|
|
|
|
cmd: ip ro
|
|
|
|
- name: proc_info
|
|
|
|
cmd: ps auxf | grep -v ]$
|
2016-08-22 20:45:42 +08:00
|
|
|
- name: systemctl_failed_info
|
|
|
|
cmd: systemctl --state=failed --no-pager
|
2016-08-08 19:38:25 +08:00
|
|
|
- name: k8s_info
|
2019-02-05 04:46:48 +08:00
|
|
|
cmd: "{{ bin_dir }}/kubectl get all --all-namespaces -o wide"
|
2016-08-08 19:38:25 +08:00
|
|
|
- name: errors_info
|
2016-11-15 00:09:52 +08:00
|
|
|
cmd: journalctl -p err --no-pager
|
2016-11-03 20:57:33 +08:00
|
|
|
- name: etcd_info
|
2020-07-20 22:26:51 +08:00
|
|
|
cmd: "{{ bin_dir }}/etcdctl endpoint --cluster health"
|
2016-12-07 18:05:30 +08:00
|
|
|
- name: calico_info
|
2019-05-03 05:24:21 +08:00
|
|
|
cmd: "{{ bin_dir }}/calicoctl node status"
|
2019-02-05 04:46:48 +08:00
|
|
|
when: '{{ kube_network_plugin == "calico" }}'
|
2016-12-07 18:05:30 +08:00
|
|
|
- name: calico_workload_info
|
2019-05-03 05:24:21 +08:00
|
|
|
cmd: "{{ bin_dir }}/calicoctl get workloadEndpoint -o wide"
|
2019-02-05 04:46:48 +08:00
|
|
|
when: '{{ kube_network_plugin == "calico" }}'
|
2016-12-07 18:05:30 +08:00
|
|
|
- name: calico_pool_info
|
2019-05-03 05:24:21 +08:00
|
|
|
cmd: "{{ bin_dir }}/calicoctl get ippool -o wide"
|
2019-02-05 04:46:48 +08:00
|
|
|
when: '{{ kube_network_plugin == "calico" }}'
|
2016-11-09 21:15:27 +08:00
|
|
|
- name: weave_info
|
2016-11-21 18:20:44 +08:00
|
|
|
cmd: weave report
|
2019-02-05 04:46:48 +08:00
|
|
|
when: '{{ kube_network_plugin == "weave" }}'
|
2016-11-09 21:15:27 +08:00
|
|
|
- name: weave_logs
|
2016-12-23 22:44:44 +08:00
|
|
|
cmd: "{{ docker_bin_dir }}/docker logs weave"
|
2019-02-05 04:46:48 +08:00
|
|
|
when: '{{ kube_network_plugin == "weave" }}'
|
2016-11-21 18:20:44 +08:00
|
|
|
- name: kube_describe_all
|
2019-02-05 04:46:48 +08:00
|
|
|
cmd: "{{ bin_dir }}/kubectl describe all --all-namespaces"
|
2016-12-23 22:44:44 +08:00
|
|
|
- name: kube_describe_nodes
|
2019-02-05 04:46:48 +08:00
|
|
|
cmd: "{{ bin_dir }}/kubectl describe nodes"
|
2016-12-07 18:05:30 +08:00
|
|
|
- name: kubelet_logs
|
|
|
|
cmd: journalctl -u kubelet --no-pager
|
2019-02-05 04:46:48 +08:00
|
|
|
- name: coredns_logs
|
|
|
|
cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l k8s-app=coredns -o jsonpath={.items..metadata.name}`;
|
|
|
|
do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
|
2016-11-09 21:15:27 +08:00
|
|
|
- name: apiserver_logs
|
2019-02-05 04:46:48 +08:00
|
|
|
cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l component=kube-apiserver -o jsonpath={.items..metadata.name}`;
|
|
|
|
do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
|
2016-11-09 21:15:27 +08:00
|
|
|
- name: controller_logs
|
2019-02-05 04:46:48 +08:00
|
|
|
cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l component=kube-controller-manager -o jsonpath={.items..metadata.name}`;
|
|
|
|
do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
|
2016-11-09 21:15:27 +08:00
|
|
|
- name: scheduler_logs
|
2019-02-05 04:46:48 +08:00
|
|
|
cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l component=kube-scheduler -o jsonpath={.items..metadata.name}`;
|
|
|
|
do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
|
2016-11-09 21:15:27 +08:00
|
|
|
- name: proxy_logs
|
2019-02-05 04:46:48 +08:00
|
|
|
cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l k8s-app=kube-proxy -o jsonpath={.items..metadata.name}`;
|
|
|
|
do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
|
2016-11-09 21:15:27 +08:00
|
|
|
- name: nginx_logs
|
2019-02-05 04:46:48 +08:00
|
|
|
cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l k8s-app=kube-nginx -o jsonpath={.items..metadata.name}`;
|
|
|
|
do {{ bin_dir }}/kubectl logs ${i} -n kube-system; done"
|
2016-11-09 21:15:27 +08:00
|
|
|
- name: flannel_logs
|
2019-02-05 04:46:48 +08:00
|
|
|
cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l app=flannel -o jsonpath={.items..metadata.name}`;
|
|
|
|
do {{ bin_dir }}/kubectl logs ${i} -n kube-system flannel-container; done"
|
|
|
|
when: '{{ kube_network_plugin == "flannel" }}'
|
2016-11-09 21:15:27 +08:00
|
|
|
- name: canal_logs
|
2019-02-05 04:46:48 +08:00
|
|
|
cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l k8s-app=canal-node -o jsonpath={.items..metadata.name}`;
|
|
|
|
do {{ bin_dir }}/kubectl logs ${i} -n kube-system flannel; done"
|
|
|
|
when: '{{ kube_network_plugin == "canal" }}'
|
2016-11-09 21:15:27 +08:00
|
|
|
- name: calico_policy_logs
|
2019-02-05 04:46:48 +08:00
|
|
|
cmd: "for i in `{{ bin_dir }}/kubectl get pods -n kube-system -l k8s-app=calico-kube-controllers -o jsonpath={.items..metadata.name}`;
|
|
|
|
do {{ bin_dir }}/kubectl logs ${i} -n kube-system ; done"
|
|
|
|
when: '{{ kube_network_plugin in ["canal", "calico"] }}'
|
|
|
|
- name: helm_show_releases_history
|
|
|
|
cmd: "for i in `{{ bin_dir }}/helm list -q`; do {{ bin_dir }}/helm history ${i} --col-width=0; done"
|
2023-07-05 11:36:54 +08:00
|
|
|
when: "{{ helm_enabled | default(true) }}"
|
2016-08-08 19:38:25 +08:00
|
|
|
|
|
|
|
logs:
|
|
|
|
- /var/log/syslog
|
|
|
|
- /var/log/daemon.log
|
|
|
|
- /var/log/kern.log
|
2016-11-03 20:57:33 +08:00
|
|
|
- /var/log/dpkg.log
|
|
|
|
- /var/log/apt/history.log
|
|
|
|
- /var/log/yum.log
|
2019-02-05 04:46:48 +08:00
|
|
|
- /var/log/messages
|
|
|
|
- /var/log/dmesg
|
2016-08-08 19:38:25 +08:00
|
|
|
|
2017-11-07 22:06:16 +08:00
|
|
|
environment:
|
2023-06-26 18:15:45 +08:00
|
|
|
ETCDCTL_API: "3"
|
2020-07-20 22:26:51 +08:00
|
|
|
ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
|
|
|
|
ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
|
|
|
|
ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
|
|
|
|
ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
|
2017-11-07 22:06:16 +08:00
|
|
|
|
2016-08-08 19:38:25 +08:00
|
|
|
tasks:
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Set etcd_access_addresses
|
2019-05-16 15:27:43 +08:00
|
|
|
set_fact:
|
2016-11-21 18:20:44 +08:00
|
|
|
etcd_access_addresses: |-
|
|
|
|
{% for item in groups['etcd'] -%}
|
|
|
|
https://{{ item }}:2379{% if not loop.last %},{% endif %}
|
|
|
|
{%- endfor %}
|
2017-04-10 23:49:17 +08:00
|
|
|
when: "'etcd' in groups"
|
2016-11-21 18:20:44 +08:00
|
|
|
|
2020-08-05 16:56:28 +08:00
|
|
|
- name: Storing commands output
|
|
|
|
shell: "{{ item.cmd }} &> {{ item.name }}"
|
2016-12-27 19:38:54 +08:00
|
|
|
failed_when: false
|
2019-05-03 05:24:21 +08:00
|
|
|
with_items: "{{ commands }}"
|
2019-02-05 04:46:48 +08:00
|
|
|
when: item.when | default(True)
|
2016-11-07 23:00:49 +08:00
|
|
|
no_log: True
|
2016-08-08 19:38:25 +08:00
|
|
|
|
|
|
|
- name: Fetch results
|
2023-06-26 18:15:45 +08:00
|
|
|
fetch:
|
|
|
|
src: "{{ item.name }}"
|
|
|
|
dest: "/tmp/{{ archive_dirname }}/commands"
|
2019-05-03 05:24:21 +08:00
|
|
|
with_items: "{{ commands }}"
|
2019-02-05 04:46:48 +08:00
|
|
|
when: item.when | default(True)
|
2017-04-10 23:49:17 +08:00
|
|
|
failed_when: false
|
2016-08-08 19:38:25 +08:00
|
|
|
|
|
|
|
- name: Fetch logs
|
2023-06-26 18:15:45 +08:00
|
|
|
fetch:
|
|
|
|
src: "{{ item }}"
|
|
|
|
dest: "/tmp/{{ archive_dirname }}/logs"
|
2019-05-03 05:24:21 +08:00
|
|
|
with_items: "{{ logs }}"
|
2019-02-05 04:46:48 +08:00
|
|
|
failed_when: false
|
2016-08-08 19:38:25 +08:00
|
|
|
|
|
|
|
- name: Pack results and logs
|
2023-06-26 18:15:45 +08:00
|
|
|
community.general.archive:
|
2019-02-05 04:46:48 +08:00
|
|
|
path: "/tmp/{{ archive_dirname }}"
|
2023-07-05 11:36:54 +08:00
|
|
|
dest: "{{ dir | default('.') }}/logs.tar.gz"
|
2018-03-13 02:59:22 +08:00
|
|
|
remove: true
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0640"
|
2018-03-13 02:59:22 +08:00
|
|
|
delegate_to: localhost
|
2020-06-25 23:14:38 +08:00
|
|
|
connection: local
|
2018-03-13 02:59:22 +08:00
|
|
|
become: false
|
2016-08-22 20:45:42 +08:00
|
|
|
run_once: true
|
|
|
|
|
|
|
|
- name: Clean up collected command outputs
|
2023-06-26 18:15:45 +08:00
|
|
|
file:
|
|
|
|
path: "{{ item.name }}"
|
|
|
|
state: absent
|
2019-05-03 05:24:21 +08:00
|
|
|
with_items: "{{ commands }}"
|