main.yml 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. - name: install duplicity
  2. apt:
  3. name: '{{duplitab_duplicity_package_name}}'
  4. state: present
  5. become: yes
  6. - name: install sshfs
  7. apt:
  8. name: sshfs
  9. state: present
  10. become: yes
  11. - name: install duplitab package
  12. copy:
  13. src: '{{duplitab_package_source_path}}'
  14. dest: '{{duplitab_package_install_path}}'
  15. become: yes
  16. register: duplitab_package
  17. - name: install duplitab
  18. apt:
  19. deb: '{{duplitab_package.dest}}'
  20. state: present
  21. become: yes
  22. - name: generate backup config
  23. set_fact:
  24. source_type: "{{item.0.source_host is defined | ternary('sshfs', 'local')}}"
  25. source_host: "{{item.0.source_host | default(None)}}"
  26. source_path: "{{item.0.source_path}}"
  27. selectors: "{{item.0.selectors|default([])}}"
  28. target_url: "{{item.1.url}}"
  29. target_via_sshfs: "{{item.1.sshfs | default(False)}}"
  30. encrypt_key: "{{item.1.encrypt_key | default(None)}}"
  31. encryption: "{{item.1.encrypt_key is defined}}"
  32. with_subelements:
  33. - '{{duplitab_backups}}'
  34. - targets
  35. register: duplitab_config
  36. - name: write /etc/duplitab
  37. copy:
  38. content: "{{duplitab_config.results | map(attribute = 'ansible_facts') | list | to_nice_yaml}}"
  39. dest: /etc/duplitab
  40. become: yes
  41. - name: setup cron jobs
  42. blockinfile:
  43. dest: '/etc/crontab'
  44. marker: '# ANSIBLE DUPLITAB BACKUPS {mark}'
  45. block: |-
  46. {% for job in duplitab_cron_jobs %}
  47. {{job.minute}} {{job.hour}} * * * {{job.local_user}} duplitab
  48. {%- if job.target_url_filter is defined %}
  49. --filter-target-url '{{job.target_url_filter}}'
  50. {%- endif %}
  51. {%- if job.quiet | default(True) %}
  52. --quiet
  53. {%- endif %}
  54. backup
  55. {% endfor %}
  56. become: yes