2016-08-08 11:38:25 +00:00
|
|
|
---
|
|
|
|
- hosts: all
|
2016-11-21 10:20:44 +00:00
|
|
|
become: true
|
2016-08-08 11:38:25 +00:00
|
|
|
gather_facts: no
|
|
|
|
|
|
|
|
vars:
|
2017-04-10 15:49:17 +00:00
|
|
|
docker_bin_dir: /usr/bin
|
|
|
|
bin_dir: /usr/local/bin
|
|
|
|
ansible_ssh_pipelining: true
|
2017-11-07 14:06:16 +00:00
|
|
|
etcd_cert_dir: /etc/ssl/etcd/ssl
|
2019-02-04 20:46:48 +00:00
|
|
|
kube_network_plugin: calico
|
|
|
|
archive_dirname: collect-info
|
2016-08-08 11:38:25 +00:00
|
|
|
commands:
|
|
|
|
- name: timedate_info
|
|
|
|
cmd: timedatectl status
|
|
|
|
- name: kernel_info
|
|
|
|
cmd: uname -r
|
|
|
|
- name: docker_info
|
2016-12-23 14:44:44 +00:00
|
|
|
cmd: "{{ docker_bin_dir }}/docker info"
|
2016-08-08 11:38:25 +00: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 12:45:42 +00:00
|
|
|
- name: systemctl_failed_info
|
|
|
|
cmd: systemctl --state=failed --no-pager
|
2016-08-08 11:38:25 +00:00
|
|
|
- name: k8s_info
|
2019-02-04 20:46:48 +00:00
|
|
|
cmd: "{{ bin_dir }}/kubectl get all --all-namespaces -o wide"
|
2016-08-08 11:38:25 +00:00
|
|
|
- name: errors_info
|
2016-11-14 16:09:52 +00:00
|
|
|
cmd: journalctl -p err --no-pager
|
2016-11-03 12:57:33 +00:00
|
|
|
- name: etcd_info
|
2019-02-04 20:46:48 +00:00
|
|
|
cmd: "{{ bin_dir }}/etcdctl --peers={{ etcd_access_addresses | default('http://127.0.0.1:2379') }} cluster-health"
|
2016-12-07 10:05:30 +00:00
|
|
|
- name: calico_info
|
2019-05-02 21:24:21 +00:00
|
|
|
cmd: "{{ bin_dir }}/calicoctl node status"
|
2019-02-04 20:46:48 +00:00
|
|
|
when: '{{ kube_network_plugin == "calico" }}'
|
2016-12-07 10:05:30 +00:00
|
|
|
- name: calico_workload_info
|
2019-05-02 21:24:21 +00:00
|
|
|
cmd: "{{ bin_dir }}/calicoctl get workloadEndpoint -o wide"
|
2019-02-04 20:46:48 +00:00
|
|
|
when: '{{ kube_network_plugin == "calico" }}'
|
2016-12-07 10:05:30 +00:00
|
|
|
- name: calico_pool_info
|
2019-05-02 21:24:21 +00:00
|
|
|
cmd: "{{ bin_dir }}/calicoctl get ippool -o wide"
|
2019-02-04 20:46:48 +00:00
|
|
|
when: '{{ kube_network_plugin == "calico" }}'
|
2016-11-09 13:15:27 +00:00
|
|
|
- name: weave_info
|
2016-11-21 10:20:44 +00:00
|
|
|
cmd: weave report
|
2019-02-04 20:46:48 +00:00
|
|
|
when: '{{ kube_network_plugin == "weave" }}'
|
2016-11-09 13:15:27 +00:00
|
|
|
- name: weave_logs
|
2016-12-23 14:44:44 +00:00
|
|
|
cmd: "{{ docker_bin_dir }}/docker logs weave"
|
2019-02-04 20:46:48 +00:00
|
|
|
when: '{{ kube_network_plugin == "weave" }}'
|
2016-11-21 10:20:44 +00:00
|
|
|
- name: kube_describe_all
|
2019-02-04 20:46:48 +00:00
|
|
|
cmd: "{{ bin_dir }}/kubectl describe all --all-namespaces"
|
2016-12-23 14:44:44 +00:00
|
|
|
- name: kube_describe_nodes
|
2019-02-04 20:46:48 +00:00
|
|
|
cmd: "{{ bin_dir }}/kubectl describe nodes"
|
2016-12-07 10:05:30 +00:00
|
|
|
- name: kubelet_logs
|
|
|
|
cmd: journalctl -u kubelet --no-pager
|
2019-02-04 20:46:48 +00: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 13:15:27 +00:00
|
|
|
- name: apiserver_logs
|
2019-02-04 20:46:48 +00: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 13:15:27 +00:00
|
|
|
- name: controller_logs
|
2019-02-04 20:46:48 +00: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 13:15:27 +00:00
|
|
|
- name: scheduler_logs
|
2019-02-04 20:46:48 +00: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 13:15:27 +00:00
|
|
|
- name: proxy_logs
|
2019-02-04 20:46:48 +00: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 13:15:27 +00:00
|
|
|
- name: nginx_logs
|
2019-02-04 20:46:48 +00: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 13:15:27 +00:00
|
|
|
- name: flannel_logs
|
2019-02-04 20:46:48 +00: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 13:15:27 +00:00
|
|
|
- name: canal_logs
|
2019-02-04 20:46:48 +00: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 13:15:27 +00:00
|
|
|
- name: calico_policy_logs
|
2019-02-04 20:46:48 +00: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"
|
|
|
|
when: "{{ helm_enabled|default(true) }}"
|
2016-08-08 11:38:25 +00:00
|
|
|
|
|
|
|
logs:
|
|
|
|
- /var/log/syslog
|
|
|
|
- /var/log/daemon.log
|
|
|
|
- /var/log/kern.log
|
2016-11-03 12:57:33 +00:00
|
|
|
- /var/log/dpkg.log
|
|
|
|
- /var/log/apt/history.log
|
|
|
|
- /var/log/yum.log
|
2019-02-04 20:46:48 +00:00
|
|
|
- /var/log/messages
|
|
|
|
- /var/log/dmesg
|
2016-08-08 11:38:25 +00:00
|
|
|
|
2017-11-07 14:06:16 +00:00
|
|
|
environment:
|
|
|
|
ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}.pem"
|
|
|
|
ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}-key.pem"
|
|
|
|
|
2016-08-08 11:38:25 +00:00
|
|
|
tasks:
|
2019-05-16 07:27:43 +00:00
|
|
|
- name: set etcd_access_addresses
|
|
|
|
set_fact:
|
2016-11-21 10:20:44 +00:00
|
|
|
etcd_access_addresses: |-
|
|
|
|
{% for item in groups['etcd'] -%}
|
|
|
|
https://{{ item }}:2379{% if not loop.last %},{% endif %}
|
|
|
|
{%- endfor %}
|
2017-04-10 15:49:17 +00:00
|
|
|
when: "'etcd' in groups"
|
2016-11-21 10:20:44 +00:00
|
|
|
|
2016-08-08 11:38:25 +00:00
|
|
|
- name: Storing commands output
|
|
|
|
shell: "{{ item.cmd }} 2>&1 | tee {{ item.name }}"
|
2016-12-27 11:38:54 +00:00
|
|
|
failed_when: false
|
2019-05-02 21:24:21 +00:00
|
|
|
with_items: "{{ commands }}"
|
2019-02-04 20:46:48 +00:00
|
|
|
when: item.when | default(True)
|
2016-11-07 15:00:49 +00:00
|
|
|
no_log: True
|
2016-08-08 11:38:25 +00:00
|
|
|
|
|
|
|
- name: Fetch results
|
2019-02-04 20:46:48 +00:00
|
|
|
fetch: src={{ item.name }} dest=/tmp/{{ archive_dirname }}/commands
|
2019-05-02 21:24:21 +00:00
|
|
|
with_items: "{{ commands }}"
|
2019-02-04 20:46:48 +00:00
|
|
|
when: item.when | default(True)
|
2017-04-10 15:49:17 +00:00
|
|
|
failed_when: false
|
2016-08-08 11:38:25 +00:00
|
|
|
|
|
|
|
- name: Fetch logs
|
2019-02-04 20:46:48 +00:00
|
|
|
fetch: src={{ item }} dest=/tmp/{{ archive_dirname }}/logs
|
2019-05-02 21:24:21 +00:00
|
|
|
with_items: "{{ logs }}"
|
2019-02-04 20:46:48 +00:00
|
|
|
failed_when: false
|
2016-08-08 11:38:25 +00:00
|
|
|
|
|
|
|
- name: Pack results and logs
|
2018-03-12 18:59:22 +00:00
|
|
|
archive:
|
2019-02-04 20:46:48 +00:00
|
|
|
path: "/tmp/{{ archive_dirname }}"
|
2018-03-12 18:59:22 +00:00
|
|
|
dest: "{{ dir|default('.') }}/logs.tar.gz"
|
|
|
|
remove: true
|
|
|
|
delegate_to: localhost
|
2020-06-25 15:14:38 +00:00
|
|
|
connection: local
|
2018-03-12 18:59:22 +00:00
|
|
|
become: false
|
2016-08-22 12:45:42 +00:00
|
|
|
run_once: true
|
|
|
|
|
|
|
|
- name: Clean up collected command outputs
|
|
|
|
file: path={{ item.name }} state=absent
|
2019-05-02 21:24:21 +00:00
|
|
|
with_items: "{{ commands }}"
|