ansible-edda/playbooks/tasks/backups/00-zfs-snapshots.d/syncoid.yml

59 lines
2.0 KiB
YAML

- 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