Skip to content

Instantly share code, notes, and snippets.

@kpfleming
Created July 24, 2022 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpfleming/41d88dc51efefe6a6817fc680541a1ab to your computer and use it in GitHub Desktop.
Save kpfleming/41d88dc51efefe6a6817fc680541a1ab to your computer and use it in GitHub Desktop.
Ansible/Jinja2 template for generatlng part of a configuration file for zrepl
{% if ansible_local.system.fact.zrepl_send_target is defined %}
{% set t = ansible_local.system.fact.zrepl_send_target %}
{% for e in zfs_filesystems|dict2items|selectattr('value.backup')|map(attribute='value.encrypted')|unique %}
- name: {{ t ~ ('-encrypted' if e else '-plain') }}
type: push
connect:
type: tcp
address: "{{ t ~ ':' ~ (sink_port_encrypted if e else sink_port_plain) }}"
send:
encrypted: {{ e|lower }}
snapshotting:
type: manual
filesystems:
{% for f in zfs_filesystems|dict2items %}
{% if f.value.encrypted == e %}
"{{ f.key ~ '<' }}": {{ f.value.backup|lower }}
{% endif %}
{% endfor %}
{% if zrepl_receive is defined %}
{% for r in zrepl_receive %}
{% if r["encrypted"] == e %}
{% for h in groups[ansible_hostname + "_zrepl_clients"] %}
{# don't send filesystems back to a client which sent them #}
{% if canonical_hostname[h]|default("") != canonical_hostname[t] %}
{% set v = hostvars[h] %}
{% for f in v["zfs_filesystems"]|dict2items %}
{% if f.value.backup and f.value.encrypted == r["encrypted"] %}
"{{ r['dest'] ~ '/' ~ v['ansible_hostname'] ~ '/' ~ f.key ~ '<' }}": true
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
pruning:
keep_sender:
- type: regex
regex: ".*"
keep_receiver:
- type: regex
regex: "^zrepl_.*"
negate: true
- type: grid
regex: "^zrepl_.*"
grid: 7x24h | 4x168h | 11x672h
{% endfor %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment