2
0
Files
Ansible/Maintenance/maint-reboot-required.yaml
2024-06-08 14:44:51 +02:00

47 lines
1.3 KiB
YAML

---
- name: Check if system reboot is required
hosts: all
become: yes
become_method: sudo
tasks:
- name: Check if a reboot is required
register: reboot
ansible.builtin.stat:
path: /var/run/reboot-required
- name: Reboot machine
command: /sbin/reboot now
poll: 0
when: reboot.stat.exists
- name: Pause for 15 seconds
ansible.builtin.pause:
seconds: 15
when: reboot.stat.exists
- name: Wait for systems to become reachable
wait_for_connection:
- name: Send Teams notification
run_once: true
uri:
url: "{{ Teams_webhook }}"
method: POST
body: |
{
"title": "Playbook: {{ ansible_play_name }}",
"text": "All servers were checked and rebooted where needed.",
"facts": [
{% for host in ansible_play_hosts_all %}
{
"name": "{{ host }}",
"value": "{% if hostvars[host]['reboot']['stat']['exists'] %}&#U+2705 Rebooted{% else %}Not Rebooted{% endif %}"
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
body_format: json
headers:
Content-Type: application/json
when: reboot.stat.exists or not reboot.stat.exists