adjust playbook to check and restart service
Merges https://pagure.io/fedora-infra/ansible/pull-request/178 Fixes https://pagure.io/fedora-infrastructure/issue/9161
This commit is contained in:
parent
1ee95304e1
commit
98aa36b59c
2 changed files with 53 additions and 0 deletions
22
playbooks/checks_log_failed_services.yml
Normal file
22
playbooks/checks_log_failed_services.yml
Normal file
|
@ -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
|
31
playbooks/restart_when_failed.yml
Normal file
31
playbooks/restart_when_failed.yml
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue