Fabian Peter Hammerle 7 years ago
commit
2766fc39bd
2 changed files with 43 additions and 0 deletions
  1. 15 0
      defaults/main.yml
  2. 28 0
      tasks/main.yml

+ 15 - 0
defaults/main.yml

@@ -0,0 +1,15 @@
+duplicity_package_name: duplicity
+duplicity_backups: []
+
+# duplicity_backups:
+# - source_path: /etc
+#   selectors:
+#   - option: include
+#     shell_pattern: /etc/apache2
+#   - option: exclude
+#     shell_pattern: /etc/**
+#   target_url: file:///backups/etc
+#   local_user: root
+#   backup_cron_jobs:
+#   - minute: 21
+#     hour: 19

+ 28 - 0
tasks/main.yml

@@ -0,0 +1,28 @@
+- name: install duplicity
+  apt:
+    name: duplicity
+    state: present
+  become: yes
+- name: generate commands
+  set_fact:
+    backup_command: |-
+      duplicity --no-encryption --no-print-statistics --verbosity warning
+      {%- for selector in item.selectors|default([]) %}
+      {% if selector['option'] in ['exclude', 'include'] %}
+       --{{selector['option']}} "{{selector['shell_pattern']}}"
+      {%- endif %}
+      {% endfor %}
+       "{{item.source_path}}" "{{item.target_url}}"
+  with_items: '{{duplicity_backups}}'
+  register: duplicity_backup_commands
+- name: setup cron jobs
+  blockinfile:
+    dest: '/etc/crontab'
+    marker: '# ANSIBLE DUPLICITY BACKUPS {mark}'
+    block: |-
+      {% for backup in duplicity_backup_commands.results %}
+      {% for backup_job in backup.item.backup_cron_jobs %}
+      {{backup_job.minute}} {{backup_job.hour}} * * * {{backup.item.local_user}} {{backup.ansible_facts.backup_command}}
+      {% endfor %}
+      {% endfor %}
+  become: yes