-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-aptpackages.yml
43 lines (38 loc) · 1.22 KB
/
update-aptpackages.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
- hosts: all
become: yes
serial: 1
tasks:
# Upgrade packages
- name: upgrade apt packages
become: yes
apt:
upgrade: yes
update_cache: yes
# Check if reboot is required
- name: check if system reboot is required
become: true
stat:
path: /var/run/reboot-required
register: reboot_required
# Send Teams message when reboot is required
- name: Send Teams message
uri:
url: "https://emblibrary.webhook.office.com/webhookb2/b73972b2-b20d-4a3e-81c5-ddd4684ac5d6@9f26c4d8-8e42-44aa-b660-81deb27aafa4/IncomingWebhook/188f776951e44235925ea0720d44f84b/01c95630-9c61-4117-95f5-92363d19bbe3"
method: POST
body_format: json
body: '{"content": "Reboot required on {{ inventory_hostname }}"}'
headers:
Content-Type: application/json
status_code: 204
when: reboot_required.stat.exists
# Rebooting the host
- name: Rebooting the host
ansible.builtin.reboot:
when: reboot_required.stat.exists
# Wait for SSH to come back
- name: Wait for SSH to come back
ansible.builtin.wait_for_connection:
delay: 60
timeout: 300
when: reboot_required.stat.exists