diff --git a/Testing/maint-reboot-required-notify.yaml b/Testing/maint-reboot-required-notify.yaml new file mode 100644 index 0000000..f6c9d77 --- /dev/null +++ b/Testing/maint-reboot-required-notify.yaml @@ -0,0 +1,33 @@ +--- +- 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 + 'ith 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 \ No newline at end of file