Skip to content

Commit

Permalink
Merge pull request #12 from aroberts/main
Browse files Browse the repository at this point in the history
Allow all Syncoid options in syncoid_syncs configuration
  • Loading branch information
exterrestris authored Feb 7, 2022
2 parents 7339bc5 + 941b88e commit 833d673
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ In order for Syncoid to replicate to a remote host, you must ensure that SSH acc
| *`setting`* | `""` | Policy setting |

All settings supported by Sanoid in templates are supported - see [sanoid.conf](https://github.com/jimsalterjrs/sanoid/blob/master/sanoid.conf) and [sanoid.defaults.conf](https://github.com/jimsalterjrs/sanoid/blob/master/sanoid.defaults.conf) for details
Similarly, most [Syncoid flags](https://github.com/jimsalterjrs/sanoid/wiki/Syncoid#options) are configurable via `syncoid_syncs`.

#### `sanoid_datasets[]`
| Variable | Default | Comments |
Expand Down Expand Up @@ -66,11 +67,11 @@ All settings supported by Sanoid in templates are supported - see [sanoid.conf](
| :--- | :--- | :--- |
| `syncoid_service_name` | `"syncoid"` | systemd service name for Syncoid |
| `syncoid_timer_frequency` | `"daily"` | systemd service frequency for Syncoid |
| `syncoid_use_ssh_key` | `yes` | Use an SSH key to login to remote hosts |
| `syncoid_generate_ssh_key` | `yes` | Generate an SSH key for Syncoid to use |
| `syncoid_generated_ssh_key` | `id_syncoid` | Name of generated SSH key |
| `syncoid_use_ssh_key` | `yes` | Use an SSH key to login to remote hosts |
| `syncoid_generate_ssh_key` | `yes` | Generate an SSH key for Syncoid to use |
| `syncoid_generated_ssh_key` | `id_syncoid` | Name of generated SSH key |
| `syncoid_ssh_key` | `/root/.ssh/{`*`syncoid_generated_ssh_key`*`\|id_rsa}` | Path to SSH key for Syncoid to use |
| `syncoid_ssh_key_install_remote` | `yes` | Install specified SSH key on remote hosts. Requires remote hosts to be defined in inventory |
| `syncoid_ssh_key_install_remote` | `yes` | Install specified SSH key on remote hosts. Requires remote hosts to be defined in inventory |

## Example

Expand Down
17 changes: 16 additions & 1 deletion tasks/install-source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ansible.builtin.package:
name: "{{ item }}"
state: present
with_items: "sanoid_prerequisites"
with_items: "{{ sanoid_prerequisites }}"

- become: false
delegate_to: localhost
Expand Down Expand Up @@ -50,6 +50,21 @@
- findoid
- sleepymutex

- name: create config directory
file:
dest: "{{ sanoid_conf_dir }}"
state: directory
owner: root
group: root

- name: copy sanoid.defaults.conf to config dir
copy:
src: "{{ sanoid_source_download_dir }}/sanoid.defaults.conf"
dest: "{{ sanoid_conf_dir }}"
remote_src: yes
mode: '0644'
become: true

- name: set paths to binaries
set_fact:
sanoid_bin_path: "{{ sanoid_source_install_dir }}/sanoid"
Expand Down
2 changes: 1 addition & 1 deletion tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
dest: "{{ sanoid_conf }}"
owner: root
group: root
mode: '0700'
mode: '0600'

- name: enable sanoid prune service
ansible.builtin.systemd:
Expand Down
63 changes: 62 additions & 1 deletion templates/syncoid.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,73 @@ After=zfs.target
Type=oneshot
{% for sync in syncoid_syncs %}
ExecStart={{ syncoid_path | default(syncoid_bin_path) }} \
{% if sync.identifier | default('') %}
--identifier={{ sync.identifier }} \
{% endif %}
{% if sync.force_delete | default(False) %}
--force-delete \
{% endif %}
{% if sync.recursive | default(False) %}
--recursive \
{% if sync.skip_parent | default(False) %}
--skip-parent \ {# only relevant if --recursive #}
{% endif %}
{% endif %}
{% if sync.compress | default('') %}
--compress={{ sync.compress }} \
{% endif %}
{% if sync.source_bwlimit | default('') %}
--source-bwlimit={{ sync.source_bwlimit }} \
{% endif %}
{% if sync.target_bwlimit | default('') %}
--target-bwlimit={{ sync.target_bwlimit }} \
{% endif %}
{% if sync.mbuffer_size | default('') %}
--mbuffer-size={{ sync.mbuffer_size }} \
{% endif %}
{% if sync.pv_options | default('') %}
--pv-options={{ sync.pv_options }} \
{% endif %}
{% if sync.no_stream | default(False) %}
--no-stream \
{% endif %}
{% if sync.no_sync_snap | default(False) %}
--no-sync-snap \
{% if sync.create_bookmark | default(False) %}
--create-bookmark \
{% endif %}
{% endif %}
{% if sync.keep_sync_snap | default(False) %}
--keep-sync-snap \
{% endif %}
{% if sync.preserve_recordsize | default(False) %}
--preserve-recordsize
{% endif %}
{% if sync.no_clone_rollback | default(False) %}
--no-clone-rollback \
{% endif %}
{% if sync.no_rollback | default(False) %}
--no-rollback \
{% endif %}
{% for sync_exclude in sync.exclude | default([]) %}
--exclude={{ sync_exclude }}
{% endfor %}
{% if sync.sendoptions | default('') %}
--sendoptions={{ sync.sendoptions }} \
{% endif %}
{% if sync.recvoptions | default('') %}
--recvoptions={{ sync.recvoptions }} \
{% endif %}
{% if sync.no_privilege_escalation | default(False) %}
--no-privilege-escalation \
{% endif %}
{% if sync.no_resume | default(False) %}
--no-resume \
{% endif %}
{% if sync.no_clone_handling | default(False) %}
--no-clone-handling \
{% endif %}

{% if syncoid_use_ssh_key | default(False) %}
--sshkey {{ syncoid_ssh_key }} \
{% endif %}
Expand All @@ -26,4 +87,4 @@ ExecStart={{ syncoid_path | default(syncoid_bin_path) }} \
{% else %}
{{ sync.dest }}
{% endif %}
{% endfor %}
{% endfor %}

0 comments on commit 833d673

Please sign in to comment.