From 23ec5073810119ac5684d1b4458ec27ed898228e Mon Sep 17 00:00:00 2001 From: Christian Segundo Date: Thu, 20 Apr 2023 10:24:53 +0200 Subject: first commit --- README.md | 29 +++++++++++++++++++++++++++++ defaults/main.yaml | 2 ++ meta/main.yml | 12 ++++++++++++ tasks/main.yaml | 28 ++++++++++++++++++++++++++++ tasks/zpool.yaml | 23 +++++++++++++++++++++++ 5 files changed, 94 insertions(+) create mode 100644 README.md create mode 100644 defaults/main.yaml create mode 100644 meta/main.yml create mode 100644 tasks/main.yaml create mode 100644 tasks/zpool.yaml diff --git a/README.md b/README.md new file mode 100644 index 0000000..b6505e6 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# zfs + +## Example playbook + +``` +- hosts: foo + vars: + roles: + - role: someone_stole_my_name.zfs + vars: + zpools: + - name: foopool + state: present + mode: mirror + mountpoint: none + devices: + - ata-ST4000VN006-5CW102_ZW60XPA3 + - ata-ST4000VN006-5CW102_ZW60XPA5 + + zvols: + - name: barvool + state: present + pool: foopool + extra_zfs_properties: + refquota: 256M + dedup: on + compression: on + mountpoint: /mnt/barvool +``` diff --git a/defaults/main.yaml b/defaults/main.yaml new file mode 100644 index 0000000..62240ea --- /dev/null +++ b/defaults/main.yaml @@ -0,0 +1,2 @@ +zpools: [] +zvols: [] diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..eec0f11 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,12 @@ +--- +galaxy_info: + description: Manage ZFS pools and volumes + role_name: zfs + namespace: someone_stole_my_name + author: Christian Segundo + license: BSD-3-Clause + min_ansible_version: "2.7" + platforms: + - name: Debian + galaxy_tags: + - zfs diff --git a/tasks/main.yaml b/tasks/main.yaml new file mode 100644 index 0000000..207006b --- /dev/null +++ b/tasks/main.yaml @@ -0,0 +1,28 @@ +- name: Install packages + block: + - apt: + name: + - linux-headers-amd64 + - zfs-dkms + - apt: + name: zfsutils-linux + default_release: "{{ ansible_distribution_release | lower }}-backports" + +- name: Add the zfs module + community.general.modprobe: + name: zfs + state: present + +- include_tasks: zpool.yaml + loop: "{{ zpools }}" + loop_control: + loop_var: zpool + +- name: Create ZVOL + community.general.zfs: + name: "{{ zvol.pool }}/{{ zvol.name }}" + state: "{{ zvol.state }}" + extra_zfs_properties: "{{ zvol.extra_zfs_properties }}" + loop: "{{ zvols }}" + loop_control: + loop_var: zvol diff --git a/tasks/zpool.yaml b/tasks/zpool.yaml new file mode 100644 index 0000000..97ba8c6 --- /dev/null +++ b/tasks/zpool.yaml @@ -0,0 +1,23 @@ +- name: Check ZFS pool existance + command: zpool list -Ho name {{ zpool.name }} + register: result_pool_list + ignore_errors: true + changed_when: false + +- name: Create ZFS pool + command: >- + zpool create + {% if zpool.options is defined and zpool.options | length > 0 %}-o {{ zpool.options | join(' -o ') }}{% endif %} + {% if zpool.mountpoint %}-m {{ zpool.mountpoint }}{% endif %} + {{ zpool.name }} + {% if zpool.mode is defined %}{{ zpool.mode }}{% endif %} + {{ zpool.devices | join(' ') }} + when: + - zpool.state | default('present') == 'present' + - result_pool_list.rc == 1 + +- name: Destroy ZFS pool + command: zpool destroy {{ zpool.name }} + when: + - zpool.state | default('present') == 'absent' + - result_pool_list.rc == 0 -- cgit v1.2.3