Move sanoid and syncoid config into fewer places

This commit is contained in:
Wojciech Kozlowski 2022-11-09 21:47:00 +01:00
parent 5b5e5fce4f
commit 522d93c71e
6 changed files with 109 additions and 73 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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') }}"

View File

@ -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

View File

@ -8,44 +8,9 @@
state: directory state: directory
mode: 0755 mode: 0755
- name: Configure sanoid - import_tasks: 00-zfs-snapshots.d/sanoid.yml
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') }}"
- name: Configure sanoid templates - import_tasks: 00-zfs-snapshots.d/syncoid.yml
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
- name: Enable syncoid service - name: Enable syncoid service
systemd: systemd: