stuvusIT.zfs-storage

zfs-storage

This role sets up ZFS on Linux, including configuring filesystems and ZVOLs (ZFS volumes). If a filesystem uses the sharenfs option, the nfs-kernel-server will be installed. NFS exports will be saved in the file /etc/exports.d/zfs-storage-ansible.exports if zfs_save_nfs_exports is enabled. The latest ZFS version is installed using ZFS PPAs from JonathanF.

Requirements

You need one of the following Linux distributions:

  • Debian stretch or buster
  • Ubuntu xenial, bionic, cosmic, or devel

The systemd service is required for scheduling pool scrubbing instead of using the system's cron jobs. The package python-jmespath is needed on the machine running this role to manage NFS correctly.

Role Variables

Name Default / Mandatory Description
zfs_parent_fs The existing parent ZFS filesystem for all filesystems and zvols, which can be added to all configurations.
zfs_storage_defaults {} A dictionary of ZFS attributes applied to all configured ZFS filesystems/zvols.
zfs_filesystems [] A list of ZFS filesystems, each defined by a name and a dictionary of attributes (mandatory for every entry).
zfs_zpools [] A list of dictionaries with mandatory name and optional scrub (boolean) key to disable scrubbing for this pool.
zvols [] A list of zvols, defined by a name and a dictionary of attributes (mandatory for every entry).
zfs_default_enable_scrub True Indicates whether zpool scrubbing is enabled by default.
zfs_scrub_frequency weekly Sets how often scrubbing occurs - existing scrubs will be canceled. Check systemd.time for valid values.
zfs_kernel_module_parameters {} A dictionary of ZFS kernel module options to set in /etc/modprobe.d/zfs.conf.
zfs_storage_drive_wwids [] A list of WWID strings of block devices in the pool. UDEV rules are created to set the IO scheduler to noop for these devices. This is necessary for partitioned or encrypted devices since ZFS only sets the scheduler to noop for entire drives.
zfs_save_nfs_exports True Indicates if the NFS export file should be saved and cleaned up (if not needed) for consistent exports across reboots.

Note: Some ZFS attributes can only be configured during creation (see man zfs): These are utf8only, normalization, and casesensitivity for filesystems, and volsize and volblocksize for ZVOLs. If you try to change these, the task will fail. volsize is required for ZVOLs.

If an attribute is missing, the ZFS default is set (even if it was previously different), except for these four attributes:

  • acltype=posixacl
  • compression=on
  • relatime=on
  • xattr=sa

You can find all default ZFS attributes in the defaults.

Besides the standard ZFS attributes listed in the man page, this role allows for automatic snapshotting with tools like zfs-auto-snapshot using the following variables, all set to False by default:

ZFS attribute Variable name in this role Description
com.sun:auto-snapshot com_sun_auto_snapshot Enables automatic snapshotting and cleanup of snapshots for the current dataset (acts as if all following attributes are set to True).
com.sun:auto-snapshot:frequent com_sun_auto_snapshot_frequent Enables snapshotting and cleanup every 15 minutes.
com.sun:auto-snapshot:hourly com_sun_auto_snapshot_hourly Enables snapshotting and cleanup every hour.
com.sun:auto-snapshot:daily com_sun_auto_snapshot_daily Enables snapshotting and cleanup every day.
com.sun:auto-snapshot:weekly com_sun_auto_snapshot_weekly Enables snapshotting and cleanup weekly.
com.sun:auto-snapshot:monthly com_sun_auto_snapshot_monthly Enables snapshotting and cleanup monthly.

Example Playbook

- hosts: zfsstorage
  roles:
    - role: zfs-storage
      zfs_parent_fs: tank
      zfs_zpools:
        - name: rpool
          scrub: False
        - name: tank
          scrub: False
      zfs_scrub_frequency: monthly
      zfs_kernel_module_parameters:
        zfs_arc_max: 30064771072 # Allow ARC to grow to 30GB
      zfs_storage_defaults:
        acltype: posixacl
        volsize: 50G
        quota: 50G
      zfs_filesystems:
        - name: testing
          attributes:
            quota: 200G
        - name: testing/wiki
          attributes:
            sharenfs: [email protected]
            compression: off
      zvols:
        - name: testing/dns01
          attributes:
            volsize: 100G
        - name: testing/ldap01
          attributes:

Result

Name Type Attributes
tank/testing filesystem acltype=posixacl, quota=200G
tank/testing/wiki filesystem acltype=posixacl, sharenfs=[email protected], compression=off, quota=50G
tank/testing/dns01 zvol volsize=100G
tank/testing/ldap01 zvol volsize=50G

The rpool won't be scrubbed, but tank will be scrubbed monthly.

License

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Author Information

Informazioni sul progetto

Configures ZFS filesystems and ZVOLs that can be shared via NFS

Installa
ansible-galaxy install stuvusIT.zfs-storage
Licenza
cc-by-sa-4.0
Download
78
Proprietario
stuvus IT Team - Studierendenvertretung Universität Stuttgart