Ansible Playbooks

Reboot Required Check

Welcome

This playbook checks if the /var/run/reboot-required file exists on the target hosts. If the file exists, it indicates that a system reboot is required, and the playbook outputs a debug message stating "Reboot is required". This helps you to identify when a reboot is necessary after system updates or changes.

* Please be aware, the coding on this site is meant to guide. Testing these scripts in a non-production environment is strongly encouraged. I take no responsibility for use of any scripts on this site or on my github repositories.


Playbook:

---
- name: Check if system reboot is required
  hosts: "{{ my_hosts | d([]) }}"
  become: true

  tasks:
    - name: Check if system reboot is required
      become: true
      ansible.builtin.stat:
        path: /var/run/reboot-required
      register: reboot_required

    - name: Report if reboot is required
      ansible.builtin.debug:
        msg: "Reboot is required"
      when: reboot_required.stat.exists

View on GitHub