144 lines
3.5 KiB
YAML
144 lines
3.5 KiB
YAML
---
|
|
|
|
- name: check if zfs kernel module exists
|
|
ansible.builtin.stat:
|
|
path: /lib/modules/{{ ansible_kernel }}/updates/dkms/zfs.ko.zst
|
|
register: zfs_module
|
|
|
|
- name: zfs install block
|
|
when: not zfs_module.stat.exists
|
|
block:
|
|
|
|
- name: add zfs repo to pacman.conf
|
|
ansible.builtin.blockinfile:
|
|
path: /etc/pacman.conf
|
|
state: present
|
|
insertafter: "EOF"
|
|
block: |
|
|
[archzfs]
|
|
Server = http://mirror.sum7.eu/archlinux/archzfs/$repo/x86_64
|
|
Server = https://mirror.biocrafting.net/archlinux/archzfs/$repo/x86_64
|
|
|
|
- name: download archzfs repo key
|
|
ansible.builtin.uri:
|
|
dest: "/tmp/{{ zfs_key_id }}"
|
|
url: https://archzfs.com/archzfs.gpg
|
|
creates: "/tmp/{{ zfs_key_id }}"
|
|
|
|
- name: install and lsign zfs key
|
|
ansible.builtin.shell:
|
|
cmd: "{{ item }}"
|
|
with_items:
|
|
- pacman-key --add /tmp/{{ zfs_key_id }}
|
|
- pacman-key --lsign-key {{ zfs_key_id }}
|
|
|
|
- name: update system
|
|
community.general.pacman:
|
|
upgrade: true
|
|
update_cache: true
|
|
|
|
- name: install zfs dkms module
|
|
community.general.pacman:
|
|
name: "{{ zfs_packages }}"
|
|
state: latest
|
|
register: zfs_installed
|
|
|
|
- name: reboot system
|
|
ansible.builtin.reboot:
|
|
post_reboot_delay: 90
|
|
when: zfs_installed is changed
|
|
|
|
- name: set zfs module parameters
|
|
ansible.builtin.template:
|
|
src: zfs.conf.j2
|
|
dest: /etc/modprobe.d/zfs.conf
|
|
owner: root
|
|
group: root
|
|
mode: 0664
|
|
|
|
- name: load zfs module
|
|
community.general.modprobe:
|
|
name: zfs
|
|
state: present
|
|
|
|
- name: enable zfs services
|
|
ansible.builtin.service:
|
|
name: "{{ item }}"
|
|
state: started
|
|
enabled: yes
|
|
loop:
|
|
- zfs-import-cache.service
|
|
- zfs-import.target
|
|
- zfs-mount.service
|
|
- zfs.target
|
|
|
|
- name: gather existing zpool facts
|
|
community.general.zpool_facts:
|
|
|
|
# - name: create zpool list
|
|
# ansible.builtin.set_fact:
|
|
# zpool_list: []
|
|
|
|
# - name: add zpools to list
|
|
# ansible.builtin.set_fact:
|
|
# zpool_list: "{{ zpool_list + [item.name] }}"
|
|
# with_items:
|
|
# "{{ ansible_zfs_pools }}"
|
|
|
|
- name: create zpools
|
|
ansible.builtin.shell:
|
|
cmd: |
|
|
zpool create \
|
|
-o ashift={{ item.ashift }} \
|
|
-o autotrim=on \
|
|
-o cachefile=/etc/zfs/zpool.cache \
|
|
-O acltype=posixacl \
|
|
-O atime=off \
|
|
-O xattr=sa \
|
|
-O mountpoint=none \
|
|
-O canmount=off \
|
|
-O devices=off \
|
|
-O compression={{ item.compression }} \
|
|
-O reservation=none \
|
|
-O refreservation=none \
|
|
-O recordsize={{ item.recordsize }} \
|
|
{{ item.name }} {{ item.type }} {{ item.disks }}
|
|
when: item.name not in ( ansible_zfs_pools | selectattr("name") | list )
|
|
with_items:
|
|
"{{ zfs_pools }}"
|
|
|
|
- name: create zfs datasets
|
|
loop: "{{ zfs_pools | subelements('datasets') }}"
|
|
community.general.zfs:
|
|
name: "{{ item.1.name }}"
|
|
state: present
|
|
extra_zfs_properties:
|
|
canmount: off
|
|
mountpoint: none
|
|
primarycache: metadata
|
|
secondarycache: none
|
|
reservation: none
|
|
refreservation: none
|
|
dedup: off
|
|
encryption: off
|
|
compression: off
|
|
volmode: dev
|
|
devices: off
|
|
atime: off
|
|
|
|
|
|
|
|
|
|
# Adjust offset from 1H to 1D in zfs-scrub-monthly@{{ zfs-pool }}.timer
|
|
|
|
# TODO enable/start zfs-scrub-monthly@{{ zfs-pool }}.timer
|
|
|
|
# TODO configure /etc/zfs/zed.d/zed.rc
|
|
|
|
# TODO enable/start zfs-zed.service
|
|
|
|
# TODO possible configure /etc/conf.d/smartdargs
|
|
|
|
# TODO configure /etc/smartd.conf
|
|
|
|
# TODO enable/start smartd.service |