main.yml 986 B

12345678910111213141516171819202122232425262728
  1. - name: install duplicity
  2. apt:
  3. name: duplicity
  4. state: present
  5. become: yes
  6. - name: generate commands
  7. set_fact:
  8. backup_command: |-
  9. duplicity --no-encryption --no-print-statistics --verbosity warning
  10. {%- for selector in item.selectors|default([]) %}
  11. {% if selector['option'] in ['exclude', 'include'] %}
  12. --{{selector['option']}} "{{selector['shell_pattern']}}"
  13. {%- endif %}
  14. {% endfor %}
  15. "{{item.source_path}}" "{{item.target_url}}"
  16. with_items: '{{duplicity_backups}}'
  17. register: duplicity_backup_commands
  18. - name: setup cron jobs
  19. blockinfile:
  20. dest: '/etc/crontab'
  21. marker: '# ANSIBLE DUPLICITY BACKUPS {mark}'
  22. block: |-
  23. {% for backup in duplicity_backup_commands.results %}
  24. {% for backup_job in backup.item.backup_cron_jobs %}
  25. {{backup_job.minute}} {{backup_job.hour}} * * * {{backup.item.local_user}} {{backup.ansible_facts.backup_command}}
  26. {% endfor %}
  27. {% endfor %}
  28. become: yes