-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_hosts.yml
107 lines (86 loc) · 2.84 KB
/
update_hosts.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
- hosts: all
become: yes
handlers:
- name: Reboot the system
include: includes/reboot_hosts.yml
tasks:
- name: Bootstrap Fedora >=23
include: includes/bootstrap_fedora.yml
- name: Update all packages on non-apt based systems
package:
name: "*"
state: latest
when: ansible_pkg_mgr != 'apt'
register: result
until: result | succeeded
retries: 3
- name: Update all packages on apt-based systems
apt:
update_cache: yes
cache_valid_time: 3600
autoremove: yes
upgrade: dist
when: ansible_pkg_mgr == 'apt'
# Begin Block
- block:
- name: Install debian-goodies if necessary [Debian]
package:
name: debian-goodies
state: present
- name: Check if services are updated [Debian]
command: checkrestart
register: service_check
changed_when: "{{ critical_service_list }}"
notify: "{{ reboot_handlers }}"
when: ansible_os_family == 'Debian'
# End Block
# Begin Block
- block:
- name: Install yum-utils if necessary [CentOS]
package:
name: yum-utils
state: present
- name: Check if services are updated [CentOS]
command: needs-restarting
register: service_check
changed_when: "{{ critical_service_list }}"
notify: "{{ reboot_handlers }}"
when: ansible_pkg_mgr == "yum"
# End block
- name: Check if services are updated [Fedora]
command: dnf needs-restarting
args:
warn: no
when: ansible_pkg_mgr == "dnf"
register: service_check
changed_when: "{{ critical_service_list }}"
notify: "{{ reboot_handlers }}"
# Begin block
- block:
- name: Check if kernel needs reboot to upgrade [RPM-based]
shell: |
[ "$(rpm -q --last kernel \
| sed -r '1!d;s|kernel-(.*\.[a-zA-Z0-9_]+) .*|\1|')" \
!= "$(uname -r)" ]
failed_when: false
register: kernel_check
changed_when: kernel_check.rc == 0
when: ansible_os_family == "RedHat"
notify: "{{ reboot_handlers }}"
- name: Check if kernel needs reboot to upgrade [Debian]
shell: |
[ "$(dpkg -l 'linux-image-*' \
| awk 'NR>=6 && NR<7{ gsub("^linux-image-","",$2); print $2 }')" \
!= "$(uname -r)" ]
failed_when: false
register: kernel_check
changed_when: kernel_check.rc == 0
when: ansible_os_family == "Debian"
notify: "{{ reboot_handlers }}"
when:
- (ansible_virtualization_type != 'lxc')
or (ansible_virtualization_type is undefined)
- (ansible_env.container is undefined)
# End Block
- meta: flush_handlers