- hosts: "{{ hosts }}" become: yes tasks: # Upgrade packages - name: upgrade apt packages become: true apt: upgrade: yes update_cache: yes # Check if reboot is required - name: check if system reboot is required become: true stat: path: /var/run/reboot-required register: reboot_required # Send Discord message when reboot is required - name: Send Discord message uri: url: "{{ discord_webhook_url }}" method: POST body_format: json body: '{"content": "Reboot required on {{ inventory_hostname }}"}' headers: Content-Type: application/json status_code: 204 when: reboot_required.stat.exists