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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
- name: Detect system architecture
shell: "echo $(uname -m)/$(uname -p)"
register: _arch_result
changed_when: false
- name: Set arch fact
set_fact:
arch: "{{ _arch_result.stdout }}"
- name: Detect FreeBSD version
shell: "uname -r"
register: _freebsd_version_result
changed_when: false
- name: Set FreeBSD version fact
set_fact:
poudriere_freebsd_version: "{{ _freebsd_version_result.stdout | regex_replace('-p[0-9]+$', '') }}"
- name: Disable resolvconf
copy:
content: "resolvconf=NO\n"
dest: /etc/resolvconf.conf
owner: root
group: wheel
mode: "0644"
- name: Set up resolv.conf
template:
src: etc_resolv.conf.j2
dest: /etc/resolv.conf
owner: root
group: wheel
mode: "0644"
- name: Install packages
package:
name: "{{ pkg_name }}"
state: present
loop:
- rsync
- dma
- jq
- curl
- bash
- git
- python312
- py312-pip
- py312-setuptools
- py312-build
- py312-installer
- py312-wheel
- python
- fastfetch
- vim
- age
- netdata
- fd-find
- poudriere
loop_control:
loop_var: pkg_name
- name: Set up sshd
template:
src: etc_ssh_sshd_config.j2
dest: /etc/ssh/sshd_config
owner: root
group: wheel
mode: "0644"
notify: Restart sshd
- name: Start sshd
service:
name: sshd
state: started
- name: Start syslogd
service:
name: syslogd
state: started
- name: Start auditd
service:
name: auditd
state: started
- name: Set up periodic.conf
template:
src: etc_periodic.conf.j2
dest: /etc/periodic.conf
owner: root
group: wheel
mode: "0644"
- name: Install .bashrc
copy:
src: root_bashrc
dest: /root/.bashrc
owner: root
group: wheel
mode: "0644"
# Jail infrastructure
# Ports tree management
- name: Deploy update-ports script
template:
src: usr_local_bin_update_ports.sh.j2
dest: /usr/local/bin/update-ports
owner: root
group: wheel
mode: "0755"
- name: Check if quarterly ports tree exists
stat:
path: /usr/ports/quarterly/Mk
register: _quarterly_exists
- name: Download quarterly ports tree
shell: /usr/local/bin/update-ports quarterly
when: not _quarterly_exists.stat.exists
- name: Check if custom ports overlay exists
shell: "ls /usr/ports/custom/ 2>/dev/null | head -1"
register: _custom_exists
changed_when: false
- name: Download custom ports overlay
shell: /usr/local/bin/update-ports custom
when: _custom_exists.stdout == ""
- name: Discover jail directories
find:
paths: "{{ playbook_dir }}/roles/jails"
patterns: "main.yml"
recurse: true
delegate_to: localhost
register: _jail_specs
- name: Load jail definitions
set_fact:
jail_defs: "{{ jail_defs | default([]) + [_content | combine({'num': _num, 'name': _name})] }}"
vars:
_content: "{{ lookup('file', item.path) | from_yaml }}"
_num: "{{ item.path | regex_replace('.*/jails/([^/]+)/.*', '\\1') | split('_') | first | int }}"
_name: "{{ item.path | regex_replace('.*/jails/([^/]+)/.*', '\\1') | regex_replace('^[0-9]+_', '') }}"
loop: "{{ _jail_specs.files | sort(attribute='path') }}"
loop_control:
label: "{{ item.path | regex_replace('.*/jails/([^/]+)/.*', '\\1') }}"
when: "'/defaults/' in item.path"
- name: Collect unique userlands
set_fact:
jail_userlands: "{{ jail_defs | map(attribute='userland') | unique | list }}"
- name: Create base ZFS datasets
community.general.zfs:
name: "{{ item.name }}"
state: present
extra_zfs_properties:
mountpoint: "{{ item.mountpoint | default(omit) }}"
loop:
- { name: "zroot/jails", mountpoint: "/usr/local/jails" }
- { name: "zroot/jails/media" }
- { name: "zroot/jails/templates" }
- { name: "zroot/jails/containers" }
- { name: "zroot/jails/volumes", mountpoint: "none" }
- { name: "zroot/storage", mountpoint: "/usr/local/jails/volumes/storage" }
- { name: "zroot/netdata_db", mountpoint: "/var/db/netdata" }
- { name: "zroot/ports", mountpoint: "/usr/ports" }
loop_control:
label: "{{ item.name }}"
- name: Create storage group
group:
name: storage
gid: 1001
- name: Create storage user
user:
name: storage
uid: 1001
group: storage
home: /nonexistent
shell: /usr/sbin/nologin
create_home: false
- name: Set storage volume permissions
file:
path: /usr/local/jails/volumes/storage
state: directory
owner: storage
group: storage
mode: "0777"
- name: Create storage directories
file:
path: "/usr/local/jails/volumes/storage/{{ item.name }}"
state: directory
owner: "1001"
group: "1001"
mode: "{{ item.mode }}"
loop:
- { name: media, mode: "0777" }
- { name: docs, mode: "0775" }
- { name: downloads, mode: "0777" }
- { name: projects-ableton, mode: "0755" }
- { name: vault, mode: "0755" }
- { name: jan-systems-2025-content, mode: "0755" }
- name: Set up userland templates
include_tasks: userland.yml
loop: "{{ jail_userlands }}"
loop_control:
loop_var: userland
- name: Deploy /etc/jail.conf
template:
src: jail.conf.j2
dest: /etc/jail.conf
owner: root
group: wheel
mode: "0644"
- name: Deploy devfs.rules
template:
src: devfs.rules.j2
dest: /etc/devfs.rules
owner: root
group: wheel
mode: "0644"
- name: Set up crontab
template:
src: etc_crontab.j2
dest: /etc/crontab
owner: root
group: wheel
mode: "0644"
notify: Restart cron
- name: Set up poudriere
include_tasks: poudriere.yml
# Repo validation gate
- name: Check if poudriere repo has packages
stat:
path: "/usr/local/poudriere/data/packages/poudriere_build-quarterly/meta"
register: _poudriere_repo
- name: "*** POUDRIERE REPO NOT READY ***"
fail:
msg: |
════════════════════════════════════════════════════════════════
POUDRIERE REPOSITORY NOT READY
════════════════════════════════════════════════════════════════
The local package repository has not been built yet.
Run the following command on the host to build packages:
poudriere-start-build
Then re-run this playbook.
════════════════════════════════════════════════════════════════
when: not _poudriere_repo.stat.exists
- name: Install custom packages from poudriere
shell: "pkg install -y -r poudriere pylogsentinel"
register: _custom_pkg
changed_when: "'Number of packages to be installed' in _custom_pkg.stdout"
- name: Deploy pylogsentinel.conf
template:
src: usr_local_etc_pylogsentinel.conf.j2
dest: /usr/local/etc/pylogsentinel.conf
owner: root
group: wheel
mode: "0644"
- name: Deploy pylogsentinel-batch-email.sh
template:
src: usr_local_bin_pylogsentinel-batch-email.sh.j2
dest: /usr/local/bin/pylogsentinel-batch-email.sh
owner: root
group: wheel
mode: "0755"
|