2
0
Files
Ansible/Testing/maint-reboot-required-notify.yaml
2024-06-17 08:55:31 +02:00

33 lines
866 B
YAML

---
- name: Check if system reboot is required with teams notification
hosts: all
become: yes
become_user: root
tasks:
- name: Check if a reboot is required
register: reboot
ansible.builtin.stat:
path: /var/run/reboot-required
- name: Reboot machine
ansible.builtin.reboot:
when: reboot.stat.exists
- name: Wait for systems to become reachable
wait_for_connection:
delay: 5
timeout: 300
- name: Collect results
set_fact:
results: >
{{ 'Reboot required on ' ~ inventory_hostname ~ ' with reboot status: ' ~ (reboot.stat.exists | ternary('True', 'False')) }}
- name: Send notification to Teams
uri:
url: "{{ Teams_webhook }}"
method: POST
body: "{{ results }}"
body_format: json
# when: reboot.stat.exists