Add borgmatic
This commit is contained in:
35
roles/borgmatic_config/tasks/main.yaml
Normal file
35
roles/borgmatic_config/tasks/main.yaml
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
- name: Fail if hosts or directories listed in borgmatic_config_targets not in borgmatic_targets.
|
||||
ansible.builtin.fail:
|
||||
msg: All backup targets and directories must be listed in borgmatic_targets.
|
||||
when: >-
|
||||
borgmatic_config_targets
|
||||
| items2dict(key_name='host', value_name='directories')
|
||||
| ansible.builtin.combine(
|
||||
borgmatic_targets | items2dict(key_name='host', value_name='directories'), list_merge='prepend_rp'
|
||||
)
|
||||
| dict2items(key_name='host', value_name='directories')
|
||||
| difference(borgmatic_targets)
|
||||
| length != 0
|
||||
|
||||
- name: Add borgmatic configuration for {{ borgmatic_config_name }}
|
||||
ansible.builtin.template:
|
||||
src: borgmatic.yaml.j2
|
||||
dest: /etc/borgmatic.d/{{ borgmatic_config_name }}.yaml
|
||||
mode: "0600"
|
||||
no_log: true
|
||||
|
||||
- name: Add systemd timer for borgmatic {{ borgmatic_config_name }}
|
||||
ansible.builtin.template:
|
||||
src: borgmatic@.timer.j2
|
||||
dest: /etc/systemd/system/borgmatic@{{ borgmatic_config_name }}.timer
|
||||
mode: "0644"
|
||||
register: _borgmatic_config_systemd_timer
|
||||
notify: Restart borgmatic timer {{ borgmatic_config_name }}
|
||||
|
||||
- name: Enable systemd timer for borgmatic {{ borgmatic_config_name }}
|
||||
ansible.builtin.systemd_service:
|
||||
name: borgmatic@{{ borgmatic_config_name }}.timer
|
||||
state: started
|
||||
enabled: true
|
||||
when: "not (ansible_check_mode and _borgmatic_config_systemd_timer.changed and _borgmatic_config_systemd_timer.diff.before == '')"
|
||||
Reference in New Issue
Block a user