From efd9292dc82ed3e56865c055baaeb4eed07e9df1 Mon Sep 17 00:00:00 2001 From: Christian Krause Date: Fri, 15 Dec 2023 11:31:51 +0100 Subject: [PATCH] enhancement: add service debug role to catch and display service errors Signed-off-by: Christian Krause --- roles/blackbox_exporter/tasks/main.yml | 6 ++++++ roles/service_debug/tasks/main.yml | 27 ++++++++++++++++++++++++++ roles/smokeping_prober/tasks/main.yml | 6 ++++++ 3 files changed, 39 insertions(+) create mode 100644 roles/service_debug/tasks/main.yml diff --git a/roles/blackbox_exporter/tasks/main.yml b/roles/blackbox_exporter/tasks/main.yml index 193dcdfd8..575bbc390 100644 --- a/roles/blackbox_exporter/tasks/main.yml +++ b/roles/blackbox_exporter/tasks/main.yml @@ -41,3 +41,9 @@ enabled: true tags: - blackbox_exporter_run + +- name: Display service errors + ansible.builtin.include_role: + name: service_debug + vars: + __service_name: blackbox_exporter diff --git a/roles/service_debug/tasks/main.yml b/roles/service_debug/tasks/main.yml new file mode 100644 index 000000000..41e0884f5 --- /dev/null +++ b/roles/service_debug/tasks/main.yml @@ -0,0 +1,27 @@ +--- + +- name: 'Run `systemctl status {{ __service_name }}`' + ansible.builtin.command: 'systemctl status {{ __service_name }}.service' + changed_when: false + failed_when: false + register: __service_status + +- name: 'Show `systemctl status` output for {{ __service_name }}' + ansible.builtin.debug: + var: __service_status.stdout_lines + changed_when: false + failed_when: false + +- name: 'Run `journalctl -x -u {{ __service_name }}`' + ansible.builtin.command: 'journalctl -x -u {{ __service_name }}.service' + changed_when: false + failed_when: false + register: __service_journal + +- name: 'Show `journalctl -x` output for {{ __service_name }}' + ansible.builtin.debug: + var: __service_journal.stdout_lines + changed_when: false + failed_when: false + +... diff --git a/roles/smokeping_prober/tasks/main.yml b/roles/smokeping_prober/tasks/main.yml index a49265ffe..661d25f79 100644 --- a/roles/smokeping_prober/tasks/main.yml +++ b/roles/smokeping_prober/tasks/main.yml @@ -61,3 +61,9 @@ - not ansible_check_mode tags: - smokeping_prober_run + +- name: Display service errors + ansible.builtin.include_role: + name: service_debug + vars: + __service_name: smokeping_prober