Create system_zfs role

This commit is contained in:
Wojciech Kozlowski 2022-12-04 17:06:18 +01:00
parent 80d622a6a4
commit a61d6a0046
22 changed files with 155 additions and 120 deletions

View File

@ -3,10 +3,5 @@
hosts: yggdrasil
tasks:
- import_tasks: tasks/hosts/zfs-conf.yml
- import_tasks: tasks/hosts/zfs-scrub.yml
- import_tasks: tasks/hosts/zfs-trim.yml
- import_tasks: tasks/hosts/zfs-extra.yml
- import_tasks: tasks/hosts/zfsutils-cron.yml
- import_tasks: tasks/hosts/ups.yml
- import_tasks: tasks/hosts/smart.yml

View File

@ -1,17 +0,0 @@
- name: Configure ZFS module via modprobe.d
copy:
src: ./filesystem/{{ ansible_hostname }}/etc/modprobe.d/zfs.conf
dest: /etc/modprobe.d/zfs.conf
mode: 0644
register: systemd_zfs_scrub_service_file
- block:
- name: Update initramfs
shell: update-initramfs -u -k all
- name: Reboot
reboot:
when:
systemd_zfs_scrub_service_file is changed

View File

@ -1,17 +0,0 @@
- name: Load hpool keys service file
copy:
src: ./filesystem/{{ ansible_hostname }}/etc/systemd/system/zfs-load-key-hpool.service
dest: /etc/systemd/system/zfs-load-key-hpool.service
mode: 0644
register: systemd_zfs_load_key_hpool_service_file
- name: SystemD daemon reload
systemd:
daemon_reload: true
when:
systemd_zfs_load_key_hpool_service_file is changed
- name: Ensure hpool keys are loaded at boot
systemd:
name: zfs-load-key-hpool.service
enabled: yes

View File

@ -1,44 +0,0 @@
- name: Zpool status mail script
template:
src: ./filesystem/{{ ansible_hostname }}/usr/local/sbin/systemd-mail-zpool-status.j2
dest: /usr/local/sbin/systemd-mail-zpool-status
mode: 0755
- name: Zfs scrub service file
copy:
src: ./filesystem/{{ ansible_hostname }}/etc/systemd/system/zfs-scrub@.service
dest: /etc/systemd/system/zfs-scrub@.service
mode: 0644
register: systemd_zfs_scrub_service_file
- name: Zfs scrub timer file
copy:
src: ./filesystem/{{ ansible_hostname }}/etc/systemd/system/zfs-scrub-monthly@.timer
dest: /etc/systemd/system/zfs-scrub-monthly@.timer
mode: 0644
register: systemd_zfs_scrub_monthly_timer_file
- name: SystemD daemon reload
systemd:
daemon_reload: true
when:
systemd_zfs_scrub_service_file is changed or
systemd_zfs_scrub_monthly_timer_file is changed
- name: Enable zfs scrub of bpool
systemd:
name: zfs-scrub-monthly@bpool.timer
enabled: yes
state: started
- name: Enable zfs scrub of rpool
systemd:
name: zfs-scrub-monthly@rpool.timer
enabled: yes
state: started
- name: Enable zfs scrub of hpool
systemd:
name: zfs-scrub-monthly@hpool.timer
enabled: yes
state: started

View File

@ -1,32 +0,0 @@
- name: Zfs trim service file
copy:
src: ./filesystem/{{ ansible_hostname }}/etc/systemd/system/zfs-trim@.service
dest: /etc/systemd/system/zfs-trim@.service
mode: 0644
register: systemd_zfs_trim_service_file
- name: Zfs trim timer file
copy:
src: ./filesystem/{{ ansible_hostname }}/etc/systemd/system/zfs-trim-monthly@.timer
dest: /etc/systemd/system/zfs-trim-monthly@.timer
mode: 0644
register: systemd_zfs_trim_monthly_timer_file
- name: SystemD daemon reload
systemd:
daemon_reload: true
when:
systemd_zfs_trim_service_file is changed or
systemd_zfs_trim_monthly_timer_file is changed
- name: Enable zfs trim of bpool
systemd:
name: zfs-trim-monthly@bpool.timer
enabled: yes
state: started
- name: Enable zfs trim of rpool
systemd:
name: zfs-trim-monthly@rpool.timer
enabled: yes
state: started

View File

@ -1,4 +0,0 @@
- name: Remove the zfsutils cron job
file:
state: absent
path: /etc/cron.d/zfsutils-linux

View File

@ -1,5 +1,11 @@
---
- name: "play : all"
- name: "play : all : zfs"
hosts: "zfs"
roles:
- role: "system_zfs"
tags: "role:system_zfs"
- name: "play : all : system"
hosts: "all"
roles:
- role: "system_mail"

View File

@ -0,0 +1,8 @@
# scrub
zpools: []
# trim
zpools_trim: []
# load-key
zpools_load_key: []

View File

@ -0,0 +1,18 @@
argument_specs:
main:
options:
ansible_hostname:
type: "str"
required: true
zpools:
type: "list"
elements: "str"
required: true
zpools_trim:
type: "list"
elements: "str"
required: true
zpools_load_key:
type: "list"
elements: "str"
required: true

View File

@ -0,0 +1,18 @@
- name: "conf : configure zfs module via modprobe.d"
ansible.builtin.copy:
src: "./conf/zfs.conf"
dest: "/etc/modprobe.d/zfs.conf"
mode: 0644
register: zfs_conf_file
- block:
- name: "conf : update initramfs"
ansible.builtin.command:
cmd: "update-initramfs -u -k all"
- name: "conf : reboot"
ansible.builtin.reboot:
when:
zfs_conf_file.changed

View File

@ -0,0 +1,4 @@
- name: "cron : remove the zfsutils cron job"
ansible.builtin.file:
state: "absent"
path: "/etc/cron.d/zfsutils-linux"

View File

@ -0,0 +1,20 @@
# TODO: drop file dependence on hpool.
- name: "load-key : zfs load key service file"
ansible.builtin.copy:
src: "./load-key/zfs-load-key-hpool.service"
dest: "/etc/systemd/system/zfs-load-key-hpool.service"
mode: 0644
register: systemd_zfs_load_key_service_file
- name: "load-key : systemd daemon reload"
ansible.builtin.systemd:
daemon_reload: true
when:
systemd_zfs_load_key_service_file.changed
- name: "load-key : enable service to load for {{ item }}"
ansible.builtin.systemd:
name: "zfs-load-key-hpool.service"
enabled: true
loop: "{{ zpools_load_key }}"

View File

@ -0,0 +1,33 @@
- name: "scrub : zpool status mail script"
ansible.builtin.template:
src: "./scrub/systemd-mail-zpool-status.j2"
dest: "/usr/local/sbin/systemd-mail-zpool-status"
mode: 0755
- name: "scrub : zfs scrub systemd service file"
ansible.builtin.copy:
src: "./scrub/zfs-scrub@.service"
dest: "/etc/systemd/system/zfs-scrub@.service"
mode: 0644
register: systemd_zfs_scrub_service_file
- name: "scrub : zfs scrub systemd timer file"
ansible.builtin.copy:
src: "./scrub/zfs-scrub-monthly@.timer"
dest: "/etc/systemd/system/zfs-scrub-monthly@.timer"
mode: 0644
register: systemd_zfs_scrub_monthly_timer_file
- name: "scrub : systemd daemon reload"
ansible.builtin.systemd:
daemon_reload: true
when:
systemd_zfs_scrub_service_file.changed or
systemd_zfs_scrub_monthly_timer_file.changed
- name: "scrub : enable and start timer for zfs scrub of {{ item }}"
ansible.builtin.systemd:
name: "zfs-scrub-monthly@{{ item }}.timer"
enabled: true
state: "started"
loop: "{{ zpools }}"

View File

@ -0,0 +1,27 @@
- name: "trim : zfs trim service file"
ansible.builtin.copy:
src: "./trim/zfs-trim@.service"
dest: "/etc/systemd/system/zfs-trim@.service"
mode: 0644
register: systemd_zfs_trim_service_file
- name: "trim : zfs trim timer file"
ansible.builtin.copy:
src: "./trim/zfs-trim-monthly@.timer"
dest: "/etc/systemd/system/zfs-trim-monthly@.timer"
mode: 0644
register: systemd_zfs_trim_monthly_timer_file
- name: "trim : systemd daemon reload"
ansible.builtin.systemd:
daemon_reload: true
when:
systemd_zfs_trim_service_file.changed or
systemd_zfs_trim_monthly_timer_file.changed
- name: "trim : enable and start timer for zfs trim of {{ item }}"
ansible.builtin.systemd:
name: "zfs-trim-monthly@{{ item }}.timer"
enabled: true
state: "started"
loop: "{{ zpools_trim }}"

View File

@ -1,3 +1,23 @@
- name: "role:system_zfs:conf"
import_tasks: "include/conf.yml"
tags: "role:system_zfs:conf"
- name: "role:system_zfs:cron"
import_tasks: "include/cron.yml"
tags: "role:system_zfs:cron"
- name: "role:system_zfs:trim"
import_tasks: "include/trim.yml"
tags: "role:system_zfs:trim"
- name: "role:system_zfs:scrub"
import_tasks: "include/scrub.yml"
tags: "role:system_zfs:scrub"
- name: "role:system_zfs:load-key"
import_tasks: "include/load-key.yml"
tags: "role:system_zfs:load-key"
- name: "role:system_zfs:fstrim"
import_tasks: "include/fstrim.yml"
tags: "role:system_zfs:fstrim"