diff --git a/playbooks/checks_log_failed_services.yml b/playbooks/checks_log_failed_services.yml new file mode 100644 index 0000000000..66db83a1e5 --- /dev/null +++ b/playbooks/checks_log_failed_services.yml @@ -0,0 +1,22 @@ +# +# This playbook lets you safely display systemd logs for failed services + +- hosts: mirrorlist_proxies + gather_facts: false + + tasks: + - name: listing failed units + shell: systemctl list-units --state failed --no-legend | awk '{ print $1 }' + register: listing_failed + + - name: check log with journalctl + shell: journalctl -lru {{ item }} -n 50 + register: display_log + with_items: "{{ listing_failed.stdout_lines[0:] }}" + + - debug: var=listing_failed.stdout_lines[0:] + + - name: display log + debug: var=display_log.stdout_lines + ignore_errors: true + when: display_log is defined diff --git a/playbooks/restart_when_failed.yml b/playbooks/restart_when_failed.yml new file mode 100644 index 0000000000..d68d2be7f3 --- /dev/null +++ b/playbooks/restart_when_failed.yml @@ -0,0 +1,31 @@ +# This playbook lets you safely display systemd logs for failed services +# and then restart it + +- hosts: mirrorlist_proxies + gather_facts: false + + tasks: + - name: listing failed units + shell: systemctl list-units --state failed --no-legend | awk '{ print $1 }' + register: listing_failed + + - name: check log with journalctl + shell: journalctl -lru {{ item }} -n 50 + register: display_log + with_items: "{{ listing_failed.stdout_lines[0:] }}" + + - debug: var=listing_failed.stdout_lines[0:] + + - name: display log + debug: var=display_log.stdout_lines + ignore_errors: true + when: display_log is defined + + - name: restart failed service + systemd: + name: "{{ item }}" + state: restarted + with_items: "{{ listing_failed.stdout_lines[0:] }}" + register: restart_service + + - debug: var=restart_service.stdout_lines