-
Notifications
You must be signed in to change notification settings - Fork 1
/
CentOS7x_Update-OS-to-Kernel4x-playbook.yml
162 lines (122 loc) · 4.86 KB
/
CentOS7x_Update-OS-to-Kernel4x-playbook.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
---
################################################################################
# description: Installs/updates OS Kernel to 4x main line on CentOS7x
# usage: ansible-playbook CentOS7x_Update-OS-to-Kernel4x-playbook.yml --extra-vars 'HostOrGroup=YourServerOrGroupNameGoesHere'
# author: Ernest G. Wilson II <[email protected]> (https://github.com/ernestgwilsonii)
# license: MIT
################################################################################
# Ansible Playbook options
# REF: http://docs.ansible.com/ansible/playbooks.html
#####################################################
- name: Update OS Kernel to 4x main line on CentOS7x
hosts: "{{ HostOrGroup|default ('FATAL ERROR --> HostOrGroup NOT SET! You must specify either a Host or a Group name!') }}"
serial: "100%"
gather_facts: False
tasks:
# rpm_key - Adds or removes a gpg key from the rpm db
# REF: http://docs.ansible.com/ansible/latest/rpm_key_module.html
#################################################################
- name: Add ELRepo GPG key
rpm_key:
state: present
key: https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# Install yum packages
# REF: http://docs.ansible.com/ansible/yum_module.html
######################################################
- name: Install wget if that package is not already present or update existing if needed
yum:
name: wget
state: latest
- name: Add ELRepo yum repository
yum:
name: http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
state: present
- name: Install yum-plugin-fastestmirror if that package is not already present or update existing if needed
yum:
name: yum-plugin-fastestmirror
state: latest
- name: Install yum-utils if that package is not already present or update existing if needed
yum:
name: yum-utils
state: latest
# Tweak settings in INI files
# REF: http://docs.ansible.com/ansible/ini_file_module.html
###########################################################
- name: Set enabled=1 for yum repository elrepo-kernel in /etc/yum.repos.d/elrepo.repo
ini_file:
dest: /etc/yum.repos.d/elrepo.repo
section: elrepo-kernel
option: enabled
value: '1'
state: present
# Install yum packages
# REF: http://docs.ansible.com/ansible/yum_module.html
######################################################
- name: Update the kernel to 4x main line
yum:
name: kernel-ml
enablerepo: elrepo-kernel
state: latest
- name: Update additional items in case the new kernel needs them!
yum:
name: '*'
state: latest
# Update various configuration files
# REF: http://docs.ansible.com/ansible/lineinfile_module.html
#############################################################
- name: Set GRUB_DEFAULT=0 in /etc/default/grub so it boots the new kernel at the top of the list
lineinfile:
dest: /etc/default/grub
state: present
regexp: '^GRUB_DEFAULT\='
line: 'GRUB_DEFAULT=0'
# Execute command(s)
# REF: http://docs.ansible.com/ansible/command_module.html
##########################################################
- name: Update grub so it boots the new kernel on next reboot
command: grub2-mkconfig -o /boot/grub2/grub.cfg
# shell - Execute commands in nodes
# REF: http://docs.ansible.com/ansible/latest/shell_module.html
###############################################################
- name: Reboot
shell: sleep 2 && /usr/sbin/shutdown -r now "Rebooting for Ansible"
async: 1
poll: 0
ignore_errors: true
- name: Waiting for reboot to complete
wait_for_connection:
delay: 30
timeout: 300
# Execute command(s)
# REF: http://docs.ansible.com/ansible/command_module.html
##########################################################
- name: Remove old kernels from the OS keeping only the current and last most recent one
command: /usr/bin/package-cleanup --oldkernels --count=1 -y
# Update various configuration files
# REF: http://docs.ansible.com/ansible/lineinfile_module.html
#############################################################
- name: Make sure /etc/yum.conf has exclude=kernel-3*
lineinfile:
dest=/etc/yum.conf
state=present
line='exclude=kernel-3*'
- name: Make sure /etc/yum.conf has exclude=kernel-headers-3*
lineinfile:
dest=/etc/yum.conf
state=present
line='exclude=kernel-headers-3*'
- name: Make sure /etc/yum.conf has exclude=kernel-tools-3*
lineinfile:
dest=/etc/yum.conf
state=present
line='exclude=kernel-tools-3*'
- name: Make sure /etc/yum.conf has exclude=kernel-tools-libs-3*
lineinfile:
dest=/etc/yum.conf
state=present
line='exclude=kernel-tools-libs-3*'
- name: Make sure /etc/yum.conf has installonly_limit=3
lineinfile:
dest=/etc/yum.conf
state=present
line='installonly_limit=3'