1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic_archiver.git synced 2024-08-16 10:09:49 +02:00

change: backups can be defined as dicts (#28)

* convert

* use loop

* clean

* combine

* change: reformat dict

* fix

* fix2

* update readme
This commit is contained in:
Matthias Leutenegger 2020-11-13 10:01:05 +01:00 committed by GitHub
parent 649f6aae0c
commit 790dae3ef4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 4 deletions

View file

@ -70,7 +70,7 @@ ansible-galaxy install arillso.restic
| `restic_install_path` | `'/usr/local/bin'` | Install location for the restic binary |
| `restic_script_dir` | `'~/restic'` | Location of the generated backup scripts |
| `restic_repos` | `{}` | A dictionary of repositories where snapshots are stored |
| `restic_backups` | `[]` | A list of dictionaries specifying the files and directories to be backed up |
| `restic_backups` | `{}` (or `[]`) | A list of dictionaries specifying the files and directories to be backed up |
| `restic_create_cron` | `false` | Should a cronjob be created for each backup |
| `restic_dir_owner` | `'{{ansible_user}}'` | The owner of all created dirs |
| `restic_dir_group` | `'{{ansible_user}}'` | The group of all created dirs |
@ -146,13 +146,18 @@ Available variables:
Example:
```yaml
restic_backups:
- name: data
data:
name: data
repo: remove
src: /path/to/data
scheduled: true
schedule_hour: 3
```
> You can also specify restic_backups as an array, which is a legacy feature and
> might be deprecated in the future. currently, the name key is used for
> namint the access and backup files
#### Exclude
the `exclude` key on a backup allows you to specify multiple files to exclude or
files to look for filenames to be excluded. You can specify the following keys:

View file

@ -32,3 +32,28 @@
keep_daily: 7
keep_monthly: 12
keep_yearly: 5
- name: Converge with dict
hosts: all
roles:
- role: ansible.restic
pre_tasks:
- name: install bzip2
package:
name: bzip2
state: present
vars:
restic_download_path: ~/restic
restic_install_path: ~/restic
restic_repos:
local:
location: /backup
password: securepassword1
init: true
restic_backups:
dicttest:
name: dicttest
src: /home
repo: local
keep_last: 4
keep_tag: deployment

View file

@ -22,5 +22,6 @@
args:
chdir: ~/restic/
with_items:
- backup-dicttest.sh
- backup-test.sh
- backup-test_stdin.sh

View file

@ -1,6 +1,12 @@
---
# tasks file for skeleton
- name: reformat dict if necessary
set_fact:
restic_backups: "{{ restic_backups|dict2items|json_query('[*].value') }}"
when:
- restic_backups | type_debug == "dict"
- name: Create backup credentials
template:
src: restic_access_Linux.j2
@ -42,8 +48,8 @@
state: present
become: true
no_log: true
with_items: '{{ restic_backups }}'
when:
- restic_create_cron
- item.name is defined
- item.scheduled | default(false)
with_items: '{{ restic_backups }}'