Check if a restart is needed with Ansible

If a restart is needed in a Linux instance, it will add a file in /var/run/reboot-required It contains the message “System restart required”.

Let’s check if the file is there with ansible!

- name: Check if restart is required
  hosts: all
    - name: Check that the reboot-requied exists
        path: /var/run/reboot-required
      register: p
    - debug:
        msg: "Reboot required"
      when: p.stat.exists