1
0
IaC/ansible/roles/zfs_repo_install/tasks/main.yml

144 lines
3.5 KiB
YAML
Raw Normal View History

2023-01-09 11:19:24 -05:00
---
- 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
2023-01-10 19:59:26 -05:00
creates: "/tmp/{{ zfs_key_id }}"
2023-01-09 11:19:24 -05:00
- 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
2023-01-10 19:59:26 -05:00
register: zfs_installed
2023-01-09 11:19:24 -05:00
- name: reboot system
ansible.builtin.reboot:
post_reboot_delay: 90
2023-01-10 19:59:26 -05:00
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
2023-01-11 22:06:45 -05:00
- zfs-import.target
2023-01-10 19:59:26 -05:00
- zfs-mount.service
- zfs.target
2023-01-09 11:19:24 -05:00
- 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 }} \
2023-01-10 19:59:26 -05:00
-O reservation=none \
-O refreservation=none \
-O recordsize={{ item.recordsize }} \
2023-01-09 11:19:24 -05:00
{{ 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
2023-01-10 19:59:26 -05:00
primarycache: metadata
2023-01-09 11:19:24 -05:00
secondarycache: none
reservation: none
refreservation: none
dedup: off
encryption: off
2023-01-10 19:59:26 -05:00
compression: off
2023-01-09 11:19:24 -05:00
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