--- - hosts: Docker become: true become_method: sudo become_user: root vars: GOTIFY_IP: xxx #[Your gotify host IP goes here] GOTIFY_PORT: xxx #[Your gotify port goes here] GOTIFY_TOKEN: xxx #[Your app token goes here] ansible_python_interpreter: /usr/bin/python3 tasks: - name: prune non-dangling images community.docker.docker_prune: containers: false images: true images_filters: dangling: false networks: false volumes: false builder_cache: false - name: Check if reboot is required stat: path: /var/run/reboot-required register: reboot_required_file - name: Show Output of required reboots debug: msg="{{ reboot_required_file.stat.exists == true }}" - name: Rebooting machine shell: sleep 2 && shutdown -r now "Ansible updates triggered" async: 1 poll: 0 ignore_errors: true when: reboot_required_file.stat.exists - name: Waiting for the machine to come back local_action: wait_for host={{ ansible_host }} state=started port=22 delay=30 become: false when: reboot_required_file.stat.exists - name: notify via Gotify uri: url: 'http://{{ GOTIFY_IP }}:{{ GOTIFY_PORT }}/message?token={{ GOTIFY_TOKEN }}' method: POST body: title: content: clean docker hosts message: content: The clean docker playbook has completed for {{ ansible_host }} and is now updated. A required reboot is {{ reboot_required_file.stat.exists == true }}. priority: content: '5' body_format: form-multipart register: result ...