-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_linux.yml
More file actions
200 lines (168 loc) · 5.12 KB
/
install_linux.yml
File metadata and controls
200 lines (168 loc) · 5.12 KB
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
# ex: set tabstop=8 softtabstop=0 expandtab shiftwidth=2 smarttab:
---
- name: Check and setup file-system
hosts: localhost
gather_facts: true
vars_files:
- "vars/{{ overwrite_distribution | default(ansible_distribution) }}.yml"
- "vars/{{ overwrite_distribution | default(ansible_distribution) }}-{{ overwrite_machine | default(ansible_machine) }}.yml"
vars:
zpool_number: "{{ '{:0>2}'.format( zpool_number ) }}"
root_zfs_pool: "zroot_{{ zpool_number }}"
distro_filesystem_path: "{{ root_zfs_pool }}/ROOT/{{ ansible_distribution }}"
roles:
- name: Check & Confirm Variables
role: check_and_confirm_variables
tags:
- check_and_confirm_variables
- name: Setup/Config Filesystem
role: setup_filesystem
tags:
- setup_filesystem
#- create_filesystem
#- mount_filesystem
- name: Install Base OS
role: strap_os
tags:
- strap_os
- name: Setup chroot environment
hosts: localhost
gather_facts: false
tags:
- pre-chroot
tasks:
- name: Pre-mounting for chroot
ansible.builtin.command:
cmd: >-
mount '{{ item.src }}' '{{ item.dest }}'
{% if item.bind | default(False) %}
--bind
{% else %}
--types '{{ item.type }}' --options '{{ item.options | join(",") }}'
{% endif %}
loop: "{{ mounting_chroot }}"
- name: Install Operation System
hosts: chroot
connection: chroot
gather_facts: true
tags:
- chroot
vars_files:
- "vars/{{ overwrite_distribution | default(ansible_distribution) }}.yml"
- "vars/{{ overwrite_distribution | default(ansible_distribution) }}-{{ overwrite_machine | default(ansible_machine) }}.yml"
vars:
ansible_chroot_exe: chroot
zpool_number: "{{ '{:0>2}'.format( zpool_number ) }}"
root_zfs_pool: "zroot_{{ zpool_number }}"
distro_filesystem_path: "{{ root_zfs_pool }}/ROOT/{{ ansible_distribution }}"
distro_filesystem_path_without_zpool: "/ROOT/{{ ansible_distribution }}"
locale:
- en_DK
- da_DK
- en_US
enable_services:
- zfs.target
- zfs-mount.service
- zfs-import.target
- zfs-import-scan.service
- systemd-networkd.service
- systemd-resolved.service
- systemd-timesyncd.service
- sshd.service
roles:
- name: Config The System For Patch Management
role: verify_system
tags:
- verify_system
- verify_system_first
vars:
no_systemd: true
- name: OS specific setup
role: os_specific_setup
tags:
- os_specific_setup
- name: Install Grub
role: grub_install
tags:
- grub_install
- install_grub
- name: Config Grub
role: grub_mkconfig
tags:
- config_grub
- name: Install Linux
role: install_linux
tags:
- install_linux
- name: Config The System For Patch Management
role: verify_system
tags:
- verify_system
- verify_system_second
vars:
no_systemd: true
post_tasks:
- name: Enable services
ansible.builtin.command:
cmd: "systemctl enable {{ item }}"
loop: "{{ enable_services }}"
tags:
- test
### TODO: Don't have the loop variables hardcoded
- name: Fake mounts for
mount:
path: "{{ item }}"
src: "none"
fstype: "none"
opts: "fake,x-systemd.requires=zfs-mount.service"
state: present
loop:
- "/var"
- "/var/log"
tags:
- test
- name: Clean up folders
file:
path: "{{ item }}"
state: absent
loop:
- /var/cache/pacman/pkg
tags:
- test
- file:
path: "{{ item }}"
state: directory
loop:
- /var/cache/pacman/pkg
tags:
- test
- name: Teardown chroot environment
hosts: localhost
gather_facts: false
tags:
- post-chroot
vars_files:
- "vars/{{ overwrite_distribution | default(ansible_distribution) }}.yml"
- "vars/{{ overwrite_distribution | default(ansible_distribution) }}-{{ overwrite_machine | default(ansible_machine) }}.yml"
tasks:
- zfs_facts:
name:
recurse: yes
- name: Initiate variable 'root_zfs_pool'
set_fact:
# the workaround is to added 'to_json | from_json' and when it work (it is magic)
root_zfs_pool: "{{ ansible_zfs_datasets | to_json | from_json | json_query(filter) | first | regex_replace('/.+', '') }}"
vars:
filter: "[?mountpoint=='{{ next_boot_mountpoint }}'].name"
- name: "Kill all process there using the {{ next_boot_mountpoint }}"
shell: sudo lsof | grep '{{ next_boot_mountpoint }}' | awk '{print $2}' | uniq | sudo xargs -r kill
- name: Umount the entire chroot envirement
ansible.builtin.command:
cmd: "umount --verbose --recursive '{{ next_boot_mountpoint }}'"
register: _result
- name: Umount the entire chroot envirement (debug)
debug:
var: _result
- name: "Export {{ root_zfs_pool }} pool"
ansible.builtin.command:
cmd: "zpool export '{{ root_zfs_pool }}'"