From 68b032c3134e3154f664b2405b27e1db7561e33a Mon Sep 17 00:00:00 2001 From: John Helmert III Date: Tue, 14 Nov 2023 20:20:52 -0800 Subject: [PATCH] roles/zfs: implement removal Signed-off-by: John Helmert III --- roles/zfs/defaults/main.yml | 14 ++++++++++++++ roles/zfs/tasks/main.yml | 20 ++++++-------------- roles/zfs/tasks/remove.yml | 12 ++++++++++++ 3 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 roles/zfs/tasks/remove.yml diff --git a/roles/zfs/defaults/main.yml b/roles/zfs/defaults/main.yml index 92c7d54..8e3c3a5 100644 --- a/roles/zfs/defaults/main.yml +++ b/roles/zfs/defaults/main.yml @@ -1,2 +1,16 @@ --- +zfs_cronjobs: + - cron.d/zfs-auto-snapshot + - cron.hourly/zfs-auto-snapshot + - cron.daily/zfs-auto-snapshot + - cron.weekly/zpool-scrub + - cron.weekly/zfs-auto-snapshot + - cron.monthly/zfs-auto-snapshot +zfs_services: + - zfs-import-cache.service + - zfs-mount.service + - zfs-share.service + - zfs-zed.service + - zfs-volume-wait.service + - zfs.target zfs: false diff --git a/roles/zfs/tasks/main.yml b/roles/zfs/tasks/main.yml index d3084ba..47f76e2 100644 --- a/roles/zfs/tasks/main.yml +++ b/roles/zfs/tasks/main.yml @@ -3,26 +3,18 @@ when: zfs ansible.builtin.copy: src: etc/{{ item }} - dest: /etc + dest: /etc/{{ item }} owner: root group: root mode: "0744" - with_items: - - cron.d - - cron.hourly - - cron.daily - - cron.weekly - - cron.monthly + with_items: "{{ zfs_cronjobs }}" - name: Start and enable zfs services when: zfs ansible.builtin.service: name: "{{ item }}" state: started enabled: true - loop: - - zfs-import-cache.service - - zfs-mount.service - - zfs-share.service - - zfs-zed.service - - zfs-volume-wait.service - - zfs.target + loop: "{{ zfs_services }}" +- name: Remove zfs configuration + when: not zfs + ansible.builtin.include_tasks: remove.yml diff --git a/roles/zfs/tasks/remove.yml b/roles/zfs/tasks/remove.yml new file mode 100644 index 0000000..6e6311f --- /dev/null +++ b/roles/zfs/tasks/remove.yml @@ -0,0 +1,12 @@ +--- +- name: Remove zfs cron jobs + ansible.builtin.file: + path: "/etc/{{ item }}" + state: absent + with_items: "{{ zfs_cronjobs }}" +- name: Stop and disable zfs services + ansible.builtin.service: + name: "{{ item }}" + state: stopped + enabled: false + loop: "{{ zfs_services }}"