diff --git a/playbooks/filesystem/yggdrasil/etc/sanoid/sanoid-service.conf b/playbooks/filesystem/yggdrasil/etc/sanoid/sanoid-service.conf deleted file mode 100644 index fe595ec..0000000 --- a/playbooks/filesystem/yggdrasil/etc/sanoid/sanoid-service.conf +++ /dev/null @@ -1,9 +0,0 @@ -[rpool/var/lib/{{ ansible_hostname }}/data/pod-{{ service_name }}] - use_template = production - recursive = yes - process_children_only = yes - -[hpool/backup/{{ ansible_hostname }}/data/pod-{{ service_name }}] - use_template = backup - recursive = yes - process_children_only = yes diff --git a/playbooks/filesystem/yggdrasil/etc/sanoid/sanoid-system.conf b/playbooks/filesystem/yggdrasil/etc/sanoid/sanoid-system.conf deleted file mode 100644 index 157747c..0000000 --- a/playbooks/filesystem/yggdrasil/etc/sanoid/sanoid-system.conf +++ /dev/null @@ -1,14 +0,0 @@ -[bpool/BOOT] - use_template = production - recursive = yes - process_children_only = yes - -[rpool/ROOT] - use_template = production - recursive = yes - process_children_only = yes - -[rpool/home] - use_template = production,home - recursive = yes - process_children_only = yes diff --git a/playbooks/filesystem/yggdrasil/etc/systemd/system/syncoid-volume-data.service.j2 b/playbooks/filesystem/yggdrasil/etc/systemd/system/syncoid-volume-data.service.j2 deleted file mode 100644 index 1e2cbe0..0000000 --- a/playbooks/filesystem/yggdrasil/etc/systemd/system/syncoid-volume-data.service.j2 +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Replicate volume data snapshots -Documentation=man:syncoid(8) -After=sanoid.service -Before=sanoid-prune.service -OnFailure=status-mail@%n.service - -[Service] -Type=oneshot -ExecStart=/usr/sbin/syncoid --recursive --skip-parent --no-sync-snap rpool/var/lib/{{ ansible_hostname }}/data hpool/backup/{{ ansible_hostname }}/data - -[Install] -WantedBy=sanoid.service diff --git a/playbooks/tasks/backups/00-zfs-snapshots.d/sanoid.yml b/playbooks/tasks/backups/00-zfs-snapshots.d/sanoid.yml new file mode 100644 index 0000000..f54467f --- /dev/null +++ b/playbooks/tasks/backups/00-zfs-snapshots.d/sanoid.yml @@ -0,0 +1,49 @@ +- name: Configure sanoid system snapshots + blockinfile: + path: /etc/sanoid/sanoid.conf + create: yes + mode: 0644 + insertbefore: "BOF" + marker: "# {mark} ANSIBLE MANAGED BLOCK SYSTEM #" + block: | + [bpool/BOOT] + use_template = production + recursive = yes + process_children_only = yes + + [rpool/ROOT] + use_template = production + recursive = yes + process_children_only = yes + + [rpool/home] + use_template = production,home + recursive = yes + process_children_only = yes + +- name: Configure sanoid service snapshots + blockinfile: + path: /etc/sanoid/sanoid.conf + insertbefore: "# BEGIN ANSIBLE MANAGED BLOCK TEMPLATES #" + marker: "# {mark} ANSIBLE MANAGED BLOCK SERVICE {{ service_name }} #" + block: | + [rpool/var/lib/{{ ansible_hostname }}/data/pod-{{ service_name }}] + use_template = production + recursive = yes + process_children_only = yes + + [hpool/backup/{{ ansible_hostname }}/data/pod-{{ service_name }}] + use_template = backup + recursive = yes + process_children_only = yes + + with_items: "{{ host_services }}" + loop_control: + loop_var: service_name + +- name: Configure sanoid templates + blockinfile: + path: /etc/sanoid/sanoid.conf + insertafter: "EOF" + marker: "# {mark} ANSIBLE MANAGED BLOCK TEMPLATES #" + block: "{{ lookup('file', './filesystem/{{ ansible_hostname }}/etc/sanoid/sanoid-templates.conf') }}" diff --git a/playbooks/tasks/backups/00-zfs-snapshots.d/syncoid.yml b/playbooks/tasks/backups/00-zfs-snapshots.d/syncoid.yml new file mode 100644 index 0000000..ea21808 --- /dev/null +++ b/playbooks/tasks/backups/00-zfs-snapshots.d/syncoid.yml @@ -0,0 +1,58 @@ +- name: Configure syncoid unit + blockinfile: + path: /etc/systemd/system/syncoid-volume-data.service + create: yes + mode: 0644 + insertbefore: "BOF" + marker: "# {mark} ANSIBLE MANAGED BLOCK UNIT" + block: | + [Unit] + Description=Replicate volume data snapshots + Documentation=man:syncoid(8) + After=sanoid.service + Before=sanoid-prune.service + OnFailure=status-mail@%n.service + register: systemd_syncoid_volume_data_unit_service_file + +- name: Configure syncoid service + blockinfile: + path: /etc/systemd/system/syncoid-volume-data.service + insertafter: "# END ANSIBLE MANAGED BLOCK UNIT" + marker: "# {mark} ANSIBLE MANAGED BLOCK SERVICE" + block: | + [Service] + Type=oneshot + register: systemd_syncoid_volume_data_service_service_file + +- name: Configure syncoid commands + blockinfile: + path: /etc/systemd/system/syncoid-volume-data.service + insertbefore: "# BEGIN ANSIBLE MANAGED BLOCK INSTALL" + marker: "# {mark} ANSIBLE MANAGED BLOCK SYNCOID {{ service_name }} #" + block: > + ExecStart=/usr/sbin/syncoid --recursive --skip-parent --no-sync-snap + rpool/var/lib/{{ ansible_hostname }}/data/pod-{{ service_name }} + hpool/backup/{{ ansible_hostname }}/data/pod-{{ service_name }} + with_items: "{{ host_services }}" + loop_control: + loop_var: service_name + register: systemd_syncoid_volume_data_syncoid_service_file + +- name: Configure syncoid install + blockinfile: + path: /etc/systemd/system/syncoid-volume-data.service + insertafter: "EOF" + marker: "# {mark} ANSIBLE MANAGED BLOCK INSTALL" + block: | + [Install] + WantedBy=sanoid.service + register: systemd_syncoid_volume_data_install_service_file + +- name: SystemD daemon reload + systemd: + daemon_reload: true + when: + systemd_syncoid_volume_data_unit_service_file is changed or + systemd_syncoid_volume_data_service_service_file is changed or + systemd_syncoid_volume_data_install_service_file is changed or + systemd_syncoid_volume_data_syncoid_service_file is changed diff --git a/playbooks/tasks/backups/00-zfs-snapshots.yml b/playbooks/tasks/backups/00-zfs-snapshots.yml index 3dc9eae..e8f81fe 100644 --- a/playbooks/tasks/backups/00-zfs-snapshots.yml +++ b/playbooks/tasks/backups/00-zfs-snapshots.yml @@ -8,44 +8,9 @@ state: directory mode: 0755 -- name: Configure sanoid - blockinfile: - path: /etc/sanoid/sanoid.conf - create: yes - insertbefore: "BOF" - marker: "# {mark} ANSIBLE MANAGED BLOCK SYSTEM #" - block: "{{ lookup('file', './filesystem/{{ ansible_hostname }}/etc/sanoid/sanoid-system.conf') }}" +- import_tasks: 00-zfs-snapshots.d/sanoid.yml -- name: Configure sanoid templates - blockinfile: - path: /etc/sanoid/sanoid.conf - insertafter: "EOF" - marker: "# {mark} ANSIBLE MANAGED BLOCK TEMPLATES #" - block: "{{ lookup('file', './filesystem/{{ ansible_hostname }}/etc/sanoid/sanoid-templates.conf') }}" - -- name: Configure sanoid for services - blockinfile: - path: /etc/sanoid/sanoid.conf - insertbefore: "# BEGIN ANSIBLE MANAGED BLOCK TEMPLATES #" - marker: "# {mark} ANSIBLE MANAGED BLOCK SERVICE {{ service_name }} #" - block: "{{ lookup('template', './filesystem/{{ ansible_hostname }}/etc/sanoid/sanoid-service.conf') }}" - - with_items: "{{ host_services }}" - loop_control: - loop_var: service_name - -- name: Copy service for {{ ansible_hostname }} data replication - template: - src: ./filesystem/{{ ansible_hostname }}/etc/systemd/system/syncoid-volume-data.service.j2 - dest: /etc/systemd/system/syncoid-volume-data.service - mode: 0644 - register: systemd_syncoid_volume_data_service_file - -- name: SystemD daemon reload - systemd: - daemon_reload: true - when: - systemd_syncoid_volume_data_service_file is changed +- import_tasks: 00-zfs-snapshots.d/syncoid.yml - name: Enable syncoid service systemd: