--- - name: Install ZFS ansible.builtin.package: name: - zfsutils-linux - zfs-dkms become: true - name: Ensure ZFS kernel module is loaded ansible.builtin.command: modprobe zfs become: true args: creates: /sys/module/zfs - name: Enable ZFS systemd services ansible.builtin.systemd: name: "{{ item }}" enabled: true state: started become: true with_items: - zfs.target - zfs-import-cache - zfs-mount - zfs-import.target - name: Check if datapool exists ansible.builtin.command: zpool list datapool register: datapool_check ignore_errors: true become: true changed_when: false - name: Check if autoexpand is enabled ansible.builtin.command: zpool get -H -o value autoexpand datapool register: autoexpand_status become: true changed_when: false - name: Enable autoexpand on datapool ansible.builtin.command: zpool set autoexpand=on datapool become: true when: autoexpand_status.stdout != "on" and datapool_check.rc == 0 register: autoexpand_result changed_when: autoexpand_result.rc == 0 - name: Ensure /mnt directory exists with proper permissions ansible.builtin.file: path: /mnt state: directory mode: "0755" become: true when: datapool_check.rc == 0 - name: Create mount points ansible.builtin.file: path: "{{ item }}" state: directory mode: "0755" become: true with_items: - /mnt/isos - /mnt/vms - /mnt/ai - /mnt/downloads - /mnt/services - /mnt/audiobooks - /mnt/music - /mnt/photos - /mnt/movies - /mnt/tvshows # - /mnt/old_backups when: datapool_check.rc == 0 - name: Mount ZFS datasets become: true mount: path: "{{ item.path }}" src: "{{ item.src }}" fstype: zfs state: mounted with_items: - { path: /mnt/isos, src: datapool/isos } - { path: /mnt/vms, src: datapool/vms } - { path: /mnt/ai, src: datapool/ai } - { path: /mnt/downloads, src: datapool/downloads } - { path: /mnt/services, src: datapool/services } - { path: /mnt/audiobooks, src: datapool/audiobooks } - { path: /mnt/music, src: datapool/music } - { path: /mnt/photos, src: datapool/photos } - { path: /mnt/movies, src: datapool/movies } - { path: /mnt/tvshows, src: datapool/tv_shows } # - { path: /mnt/old_backups, src: datapool/old_backups } when: datapool_check.rc == 0 - name: Set ownership after mounting ansible.builtin.file: path: "{{ item }}" state: directory recurse: false mode: "0755" owner: menno group: users become: true with_items: - /mnt/isos - /mnt/vms - /mnt/ai - /mnt/downloads - /mnt/services - /mnt/audiobooks - /mnt/music - /mnt/photos - /mnt/movies - /mnt/tvshows # - /mnt/old_backups when: datapool_check.rc == 0 # This is needed to actually set the mountpoints in ZFS so they are persistent after reboots! - name: Set ZFS mountpoints community.general.zfs: name: "{{ item.src }}" state: present extra_zfs_properties: mountpoint: "{{ item.path }}" become: true with_items: - { path: /mnt/isos, src: datapool/isos } - { path: /mnt/vms, src: datapool/vms } - { path: /mnt/ai, src: datapool/ai } - { path: /mnt/downloads, src: datapool/downloads } - { path: /mnt/services, src: datapool/services } - { path: /mnt/audiobooks, src: datapool/audiobooks } - { path: /mnt/music, src: datapool/music } - { path: /mnt/photos, src: datapool/photos } - { path: /mnt/movies, src: datapool/movies } - { path: /mnt/tvshows, src: datapool/tv_shows } register: zfs_mountpoints_result when: datapool_check.rc == 0