123456789101112131415161718192021222324252627282930313233343536373839404142 |
- - name: install duplicity
- apt:
- name: duplicity
- state: present
- become: yes
- - name: generate commands
- set_fact:
- backup_command: |-
- {% if item.source_host is defined %}
- mount_path="$(mktemp --tmpdir --directory ansible-duplicity-sshfs-XXXXXXXX)"; sshfs "{{item.source_host}}:{{item.source_path}}" $mount_path;
- {%- endif %}
- 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 %}
- {%- if item.source_host is defined %}
- --name "{{item.source_host}}:{{item.source_path}}"
- {%- endif %}
- {%- if item.source_host is defined %}
- --allow-source-mismatch "$mount_path"
- {%- else %}
- "{{item.source_path}}"
- {%- endif %}
- "{{item.target_url}}";
- {%- if item.source_host is defined %}
- fusermount -u "$mount_path" && rm -r "$mount_path";
- {%- endif %}
- 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
|