-
Notifications
You must be signed in to change notification settings - Fork 14
/
playbook_lts_kernel.yml
178 lines (147 loc) · 5.98 KB
/
playbook_lts_kernel.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
---
- name: playbook_lts_kernel.yml - switch to more stable kernel
hosts: all
gather_facts: no
become: yes
vars:
uefi_detected: false
grub_detected: false
systemd_boot_detected: false
tasks:
# ----------------------------------------------------------------------------
# ---------------------- DETECTION ---------------------------------------
# ----------------------------------------------------------------------------
# UEFI DETECTION ------------------------------------------------------------
- name: uefi detection
stat:
path: "/sys/firmware/efi"
register: output_efi_check
- name: set uefi_detected to true if detected
set_fact:
uefi_detected: true
when: output_efi_check.stat.exists
# SYSTEMD-BOOT DETECTION ----------------------------------------------------
- name: systemd-boot detection
shell: bootctl is-installed
ignore_errors: yes
args:
executable: /usr/bin/bash
register: output_bootctl_is_inst
- name: set systemd_boot_detected to true if detected
set_fact:
systemd_boot_detected: true
when: output_bootctl_is_inst.stdout == 'yes'
# GRUB DETECTION ------------------------------------------------------------
- name: grub detection
stat:
path: "/boot/grub/grub.cfg"
register: output_grub_cfg_check
- name: set grub_detected to true if detected
set_fact:
grub_detected: true
when: output_grub_cfg_check.stat.exists
# DETECTION RESULTS AND EARLY TERMINATION OF THE PLAYBOOK --------------------
- debug: msg="uefi_detected - {{ uefi_detected }}"
- debug: msg="systemd_boot_detected - {{ systemd_boot_detected }}"
- debug: msg="grub_detected - {{ grub_detected }}"
- name: end the playbook if both grub and systemd-boot are detected
meta: end_host
when:
- systemd_boot_detected == true
- grub_detected == true
- name: end the playbook if neither grub nor systemd-boot are detected
meta: end_host
when:
- systemd_boot_detected == false
- grub_detected == false
- name: end the playbook if grub and uefi are detected
meta: end_host
when:
- grub_detected == true
- uefi_detected == true
# ----------------------------------------------------------------------------
# ---------------------- INSTALL -----------------------------------------
# ----------------------------------------------------------------------------
- name: install linux-lts
pacman:
update_cache: yes
name:
- linux-lts
when:
- systemd_boot_detected == true or grub_detected == true
# ----------------------------------------------------------------------------
# ---------------------- SYSTEMD-BOOT ------------------------------------
# ----------------------------------------------------------------------------
- name: get the path of the current default systemd-boot config file
shell: "bootctl list | grep -m1 source | awk '{print $2}'"
args:
executable: /usr/bin/bash
register: output_bootctl
when: systemd_boot_detected == true
- name: make a copy of the current default config file
copy:
src: "{{ output_bootctl.stdout }}"
dest: /boot/loader/entries/arch_lts.conf
remote_src: yes
mode: '0644'
when: systemd_boot_detected == true
- name: change the copied config to point at lts stuff
lineinfile:
path: /boot/loader/entries/arch_lts.conf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
loop:
- { regexp: '^title.+$', line: 'title Arch Linux (linux-lts)' }
- { regexp: '^title.+$', line: 'title Arch Linux (linux-lts)' }
- { regexp: '^linux.+$', line: 'linux /vmlinuz-linux-lts' }
- { regexp: '^initrd.+$', line: 'initrd /initramfs-linux-lts.img' }
when: systemd_boot_detected == true
- name: add sort-key to the config to move the lts boot menu entry to the top
lineinfile:
path: /boot/loader/entries/arch_lts.conf
line: 'sort-key arch'
when: systemd_boot_detected == true
- name: set the lts config as default
lineinfile:
path: /boot/loader/loader.conf
line: 'default arch_lts.conf'
when: systemd_boot_detected == true
- name: make a copy of the arch_lts to create fallback initramfs version
copy:
src: /boot/loader/entries/arch_lts.conf
dest: /boot/loader/entries/arch_lts_fallback.conf
remote_src: yes
mode: '0644'
when: systemd_boot_detected == true
- name: change in the fallback config initramfs path
lineinfile:
path: /boot/loader/entries/arch_lts_fallback.conf
regexp: '^initrd.+$'
line: 'initrd /initramfs-linux-lts-fallback.img'
when: systemd_boot_detected == true
- name: remove sort-key from the fallback config, to prevent fallback being top in boot menu
lineinfile:
path: /boot/loader/entries/arch_lts_fallback.conf
line: 'sort-key arch'
state: absent
when: systemd_boot_detected == true
# ----------------------------------------------------------------------------
# ---------------------- UNINSTALL REGULAR KERNEL ------------------------
# ----------------------------------------------------------------------------
- name: unisntall regular linux kernel
pacman:
name:
- linux
state: absent
when:
- systemd_boot_detected == true or grub_detected == true
# ----------------------------------------------------------------------------
# ---------------------- GRUB --------------------------------------------
# ----------------------------------------------------------------------------
- name: execute "grub-mkconfig -o /boot/grub/grub.cfg"
shell: grub-mkconfig -o /boot/grub/grub.cfg
args:
executable: /usr/bin/bash
when:
- grub_detected == true
- uefi_detected == false