-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbook.yml
236 lines (211 loc) · 7.93 KB
/
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
---
- name: Live CD playbook
hosts: "{{ hosts }}"
gather_facts: false
become: true
vars_files:
- ./vars.yml
tasks:
- name: Check that working and destination folders are set
ansible.builtin.fail: msg="Please set {{ item.name }} path with no trailing hash in vars.yml"
when: not item.path or item.path[-1] == "/"
with_items:
- {name: working_folder, path: "{{ working_folder }}"}
- {name: destination_folder, path: "{{ destination_folder }}"}
- name: Check other required variables are set
ansible.builtin.fail: msg="Please set {{ item.name }} in vars.yml"
when: not item.value or item.value|string == ''
with_items:
- {name: user, value: "{{ user }}"}
- {name: group, value: "{{ group }}"}
- {name: user_password, value: "{{ user_password }}"}
- {name: root_password, value: "{{ root_password }}"}
- {name: debian_mirror, value: "{{ debian_mirror }}"}
- name: Install applications we need to build the environment
ansible.builtin.apt:
name: "{{ item }}"
state: present
update_cache: true
with_items:
- debootstrap
- squashfs-tools
- xorriso
- isolinux
- syslinux-efi
- grub-pc-bin
- grub-efi-amd64-bin
- grub-efi-ia32-bin
- mtools
- dosfstools
- name: Remove the working folder if it already exists
ansible.builtin.file:
path: "{{ working_folder }}"
state: absent
- name: Create the working folder where we store all the files
ansible.builtin.file:
path: "{{ working_folder }}"
state: directory
owner: "{{ user }}"
group: "{{ group }}"
mode: 0755
- name: Bootstrap and configure Debian
ansible.builtin.command: >
/usr/sbin/debootstrap
--arch=amd64
--variant=minbase
bookworm
{{ working_folder }}/chroot
{{ debian_mirror }}
args:
creates: "{{ working_folder }}/chroot"
- name: Template Gnome Desktop Manager install script file
ansible.builtin.template:
src: gdm_install.j2
dest: "{{ working_folder }}/chroot/gdm_install.sh"
owner: "{{ user }}"
group: "{{ group }}"
mode: 0744
- name: Run configuration and install custom packages
ansible.builtin.command: /usr/sbin/chroot {{ working_folder }}/chroot ./gdm_install.sh
- name: Create directories that will contain files for our live environment files and scratch files
ansible.builtin.file:
path: "{{ working_folder }}/{{ item }}"
state: directory
mode: 0755
with_items:
- staging/EFI/BOOT
- staging/boot/grub/x86_64-efi
- staging/isolinux
- staging/live
- tmp
- name: Compress the chroot environment into a squash filesystem
ansible.builtin.command: >
mksquashfs
{{ working_folder }}/chroot
{{ working_folder }}/staging/live/filesystem.squashfs
-e boot
args:
creates: "{{ working_folder }}/staging/live/filesystem.squashfs"
- name: Find vmlinuz
ansible.builtin.find:
paths: "{{ working_folder }}/chroot/boot/"
file_type: file
patterns: "vmlinuz-*"
register: vmlinuz
- name: Copy the kernel from inside the chroot to the live directory
ansible.builtin.copy:
src: "{{ vmlinuz['files'][0]['path'] }}"
dest: "{{ working_folder }}/staging/live/vmlinuz"
remote_src: "{{ false if hosts == 'localhost' else true }}"
mode: 0644
- name: Find initrd
ansible.builtin.find:
paths: "{{ working_folder }}/chroot/boot/"
file_type: file
patterns: "initrd.img-*"
register: initrd
- name: Copy the initramfs from inside the chroot to the live directory
ansible.builtin.copy:
src: "{{ initrd['files'][0]['path'] }}"
dest: "{{ working_folder }}/staging/live/initrd"
remote_src: "{{ false if hosts == 'localhost' else true }}"
mode: 0644
- name: Create boot menu (BIOS/legacy mode)
ansible.builtin.copy:
src: ./files/isolinux.cfg
dest: "{{ working_folder }}/staging/isolinux/isolinux.cfg"
mode: 0644
- name: Create boot menu (EFI/UEFI mode) and copy file to EFI BOOT directory
ansible.builtin.copy:
src: ./files/grub.cfg
dest: "{{ working_folder }}/staging/{{ item }}"
mode: 0644
with_items:
- boot/grub/grub.cfg
- EFI/BOOT/grub.cfg
- name: Create boot menu (EFI/UEFI mode)
ansible.builtin.copy:
src: ./files/grub-embed.cfg
dest: "{{ working_folder }}/tmp/grub-embed.cfg"
mode: 0644
- name: Copy BIOS/legacy boot required files into our workspace
ansible.builtin.copy:
src: /usr/lib/ISOLINUX/isolinux.bin
dest: "{{ working_folder }}/staging/isolinux/"
remote_src: "{{ false if hosts == 'localhost' else true }}"
mode: 0644
- name: Copy BIOS/legacy boot required files into our workspace (2)
ansible.builtin.copy:
src: /usr/lib/syslinux/modules/bios/
dest: "{{ working_folder }}/staging/isolinux/"
remote_src: "{{ false if hosts == 'localhost' else true }}"
mode: 0644
- name: Copy EFI/modern boot required files into our workspace
ansible.builtin.copy:
src: /usr/lib/grub/x86_64-efi/
dest: "{{ working_folder }}/staging/boot/grub/x86_64-efi/"
remote_src: "{{ false if hosts == 'localhost' else true }}"
mode: 0644
- name: Generate an EFI bootable GRUB image (32)
ansible.builtin.command: >
grub-mkstandalone -O i386-efi
--modules="part_gpt part_msdos fat iso9660"
--locales=""
--themes=""
--fonts=""
--output="{{ working_folder }}/staging/EFI/BOOT/BOOTIA32.EFI"
"boot/grub/grub.cfg={{ working_folder }}/tmp/grub-embed.cfg"
args:
creates: "{{ working_folder }}/staging/EFI/BOOT/BOOTIA32.EFI"
- name: Generate an EFI bootable GRUB image (64)
ansible.builtin.command: >
grub-mkstandalone -O x86_64-efi
--modules="part_gpt part_msdos fat iso9660"
--locales=""
--themes=""
--fonts=""
--output="{{ working_folder }}/staging/EFI/BOOT/BOOTx64.EFI"
"boot/grub/grub.cfg={{ working_folder }}/tmp/grub-embed.cfg"
args:
creates: "{{ working_folder }}/staging/EFI/BOOT/BOOTx64.EFI"
- name: Create a FAT16 UEFI boot disk image containing the EFI bootloaders
ansible.builtin.command: " {{ item }} "
with_items:
- dd if=/dev/zero of=efiboot.img bs=1M count=20
- /usr/sbin/mkfs.vfat efiboot.img
- mmd -i efiboot.img ::/EFI ::/EFI/BOOT
- >
mcopy -vi efiboot.img
EFI/BOOT/BOOTIA32.EFI
EFI/BOOT/BOOTx64.EFI
boot/grub/grub.cfg
::/EFI/BOOT/
- touch {{ working_folder }}/boot_disk_done
args:
chdir: "{{ working_folder }}/staging"
creates: "{{ working_folder }}/boot_disk_done"
- name: Generate the .iso disc image file into destination folder
ansible.builtin.command: >
xorriso
-as mkisofs
-iso-level 3
-o {{ destination_folder }}/debian-live.iso
-full-iso9660-filenames
-volid "DEBLIVE"
--mbr-force-bootable -partition_offset 16
-joliet -joliet-long -rational-rock
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin
-eltorito-boot
isolinux/isolinux.bin
-no-emul-boot
-boot-load-size 4
-boot-info-table
--eltorito-catalog isolinux/isolinux.cat
-eltorito-alt-boot
-e --interval:appended_partition_2:all::
-no-emul-boot
-isohybrid-gpt-basdat
-append_partition 2 C12A7328-F81F-11D2-BA4B-00A0C93EC93B {{ working_folder }}/staging/efiboot.img
{{ working_folder }}/staging
args:
creates: "{{ destination_folder }}/debian-live.iso"