--- - name: Deploy conditional reboot service and timer hosts: all become: yes tasks: - name: Copy conditional-reboot.service file copy: dest: /etc/systemd/system/conditional-reboot.service content: | [Unit] Description=Service to conditionally reboot the system if /var/run/reboot-required exists [Service] Type=oneshot ExecStart=/bin/sh -c 'if [ -f /var/run/reboot-required ]; then reboot; fi' notify: - reload systemd - name: Copy conditional-reboot.timer file copy: dest: /etc/systemd/system/conditional-reboot.timer content: | [Unit] Description=Timer to run conditional reboot service daily at 1:30 AM [Timer] OnCalendar=daily 01:30:00 Persistent=true [Install] WantedBy=timers.target notify: - reload systemd - name: Enable and start conditional-reboot.timer systemd: name: conditional-reboot.timer enabled: yes state: started handlers: - name: reload systemd systemd: daemon_reload: yes