From 5c905cde20cb7a9d9b73cf75a35d7b3a6be81a6b Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Wed, 12 Mar 2025 10:34:54 +0100 Subject: [PATCH] feat: add check for datapool existence before creating mount points and setting permissions --- config/ansible/tasks/servers/zfs.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config/ansible/tasks/servers/zfs.yml b/config/ansible/tasks/servers/zfs.yml index a6ab1dd..d32fd72 100644 --- a/config/ansible/tasks/servers/zfs.yml +++ b/config/ansible/tasks/servers/zfs.yml @@ -23,12 +23,20 @@ - 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: 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: @@ -50,6 +58,7 @@ - /mnt/services - /mnt/stash - /mnt/tvshows + when: datapool_check.rc == 0 - name: Mount ZFS datasets become: true @@ -72,6 +81,7 @@ - { path: /mnt/services, src: datapool/services } - { path: /mnt/stash, src: datapool/stash } - { path: /mnt/tvshows, src: datapool/tv_shows } + when: datapool_check.rc == 0 - name: Set ownership after mounting ansible.builtin.file: @@ -96,3 +106,4 @@ - /mnt/services - /mnt/stash - /mnt/tvshows + when: datapool_check.rc == 0