- hosts: localhost tasks: - name: Check if reboot required file exists stat: path: /var/run/reboot-required register: reboot_file - name: Set fact if reboot is required set_fact: reboot_required: "{{ 1 if reboot_file.stat.exists else 0 }}" - name: Print reboot status debug: msg: "Reboot required: {{ reboot_file.stat.exists }}"