26 lines
699 B
YAML
26 lines
699 B
YAML
---
|
|
# Check if reboot is required on Linux servers
|
|
|
|
- name: Linux server reboot check
|
|
hosts: servers
|
|
gather_facts: true
|
|
become: true
|
|
|
|
tasks:
|
|
- name: Check if reboot is required (RHEL-compatible)
|
|
ansible.builtin.shell:
|
|
cmd: /bin/needs-restarting -r
|
|
register: needs_restarting
|
|
when: ansible_facts["os_family"] == "RedHat"
|
|
changed_when: needs_restarting.rc == 1
|
|
ignore_errors: true
|
|
|
|
- name: Reboot the machine (Wait for 5 min)
|
|
ansible.builtin.reboot:
|
|
reboot_timeout: 300
|
|
when:
|
|
- needs_restarting.rc is defined
|
|
- needs_restarting.rc == 1
|
|
- ansible_facts["os_family"] == "RedHat"
|
|
ignore_errors: true
|