-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansible-packer.yml
160 lines (134 loc) · 4.48 KB
/
ansible-packer.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
- name: Tasks to run from within packer
hosts: default
vars:
zfs_version: "2.2.0"
tasks:
# - name: Add sshkey
# ansible.posix.authorized_key:
# user: "root"
# state: present
# manage_dir: false
# path: /root/.ssh/authorized_keys
# key: "{{ lookup('file', '~/.ssh/id_ed25519.pub') }}"
- name: Move backup partition table to end
ansible.builtin.command: sgdisk -e /dev/sda
changed_when: false
- name: Read device information (always use unit when probing)
community.general.parted:
device: /dev/sda
unit: MiB
register: sda_info
- name: Resize first partition
community.general.parted:
device: /dev/sda
number: 1
state: present
part_start: "258MiB"
part_end: "10GiB"
resize: true
label: gpt
name: rootfs
- name: Add second partition
community.general.parted:
device: /dev/sda
number: 2
state: present
part_start: "10485760KiB"
part_end: "99%"
resize: true
label: gpt
name: home
- name: Packages to build ZFS
ansible.builtin.apt:
name:
- "linux-headers-{{ ansible_kernel }}"
- build-essential
- autoconf
- automake
- libtool
- gawk
- alien
- fakeroot
- dkms
- libblkid-dev
- uuid-dev
- libudev-dev
- libssl-dev
- zlib1g-dev
- libaio-dev
- libattr1-dev
- libelf-dev
- python3
- python3-dev
- python3-setuptools
- python3-cffi
- libffi-dev
- python3-packaging
- git
install_recommends: false
update_cache: true
- name: Define ZFS directory
set_fact:
zfs_dir: "/root/zfs-{{ zfs_version }}"
- name: "Get zfs release {{ zfs_version }}"
ansible.builtin.unarchive:
src: "https://github.com/openzfs/zfs/releases/download/zfs-{{ zfs_version }}/zfs-{{ zfs_version }}.tar.gz"
dest: "{{ zfs_dir | dirname }}"
remote_src: true
- name: Run autogen
ansible.builtin.shell:
cmd: sh autogen.sh
chdir: "{{ zfs_dir }}"
- name: Run ./configure
ansible.builtin.shell:
cmd: ./configure
chdir: "{{ zfs_dir }}"
# - name: run make
# ansible.builtin.shell:
# cmd: "make -s -j{{ ansible_processor_vcpus }}"
# chdir: "{{ zfs_dir }}"
- name: run make deb
ansible.builtin.shell:
cmd: "make -s -j{{ ansible_processor_vcpus }} deb"
chdir: "{{ zfs_dir }}"
- set_fact:
zfs_dir: /root/zfs-{{ zfs_version }}
- name: Find deb packages to install
find:
paths: "{{ zfs_dir }}"
depth: 1
patterns: "*.deb"
register: deb_packages
- debug:
msg: "{{ item }}"
loop:
- "{{ deb_packages.files | map(attribute='path') | reject('equalto', zfs_dir + '/zfs-dkms_{{ zfs_version }}-1_amd64.deb') }}"
- "{{ deb_packages.files | map(attribute='path') }}"
- "{{ deb_packages.files | map(attribute='path') | reject('contains', 'zfs-dkms') }}"
- name: all zfs packages except zfs-dkms
apt:
deb: "{{ item }}"
loop: "{{ deb_packages.files | map(attribute='path') | reject('contains', 'zfs-dkms') }}"
- name: Add zfs module
community.general.modprobe:
name: zfs
state: present
- set_fact:
#home_size: 10G
home_size: all
- name: aktive zfs
command: /sbin/modprobe zfs
- name: Read device information (always use unit when probing)
community.general.parted: device=/dev/sda unit=MiB
register: sda_info
- pause:
- name: create new pool
shell: /usr/sbin/zpool create -f -o compatibility=ubuntu-20.04 -o autotrim=on -o autoexpand=on -o ashift=12 -O atime=off -O dedup=off -O canmount=off -O compression=lz4 -O normalization=formD -O mountpoint=none tank /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_*-part2
- name: create home dataset on pool
command: /usr/sbin/zfs create -o setuid=off -o mountpoint=/home tank/home
- name: create lxd dataset on pool
command: /usr/sbin/zfs create -o mountpoint=/var/lib/lxd tank/lxd
- name: create podman (containers) dataset on pool
command: /usr/sbin/zfs create -o mountpoint=/var/lib/containers tank/containers
- name: export pool
command: /usr/sbin/zpool export tank