2
0
Files
Ansible/Testing/maint-reboot-required-notify.yaml

46 lines
1.2 KiB
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
when: reboot.stat.exists
- name: Collect results
set_fact:
results: >
{{ 'Reboot required on ' ~ inventory_hostname ~ ' with reboot status: ' ~ (reboot.stat.exists | ternary('True', 'False')) }}
- name: Consolidate results
set_fact:
consolidated_results: "{{ consolidated_results | default([]) + [results] }}"
run_once: true
delegate_to: localhost
- name: Send notification to Teams
uri:
url: "{{ Teams_webhook }}"
method: POST
body: |
{
"text": "{{ '\n'.join(consolidated_results) }}"
}
body_format: json
run_once: true
become: no
delegate_to: localhost
when: consolidated_results | length > 0