Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

98 lines
3.5 KiB

  1. ---
  2. - name: Ensure borg paths exist
  3. file:
  4. path: "{{ item.path }}"
  5. state: directory
  6. mode: 0750
  7. owner: "{{ matrix_user_username }}"
  8. group: "{{ matrix_user_groupname }}"
  9. with_items:
  10. - {path: "{{ matrix_backup_borg_config_path }}", when: true}
  11. - {path: "{{ matrix_backup_borg_docker_src_files_path }}", when: true}
  12. when: "item.when|bool"
  13. - name: Ensure borg config is created
  14. template:
  15. src: "{{ role_path }}/templates/config.yaml.j2"
  16. dest: "{{ matrix_backup_borg_config_path }}/config.yaml"
  17. owner: "{{ matrix_user_username }}"
  18. group: "{{ matrix_user_groupname }}"
  19. mode: 0640
  20. - name: Ensure borg passwd is created
  21. template:
  22. src: "{{ role_path }}/templates/passwd.j2"
  23. dest: "{{ matrix_backup_borg_config_path }}/passwd"
  24. owner: "{{ matrix_user_username }}"
  25. group: "{{ matrix_user_groupname }}"
  26. mode: 0640
  27. - name: Ensure borg ssh key is created
  28. template:
  29. src: "{{ role_path }}/templates/sshkey.j2"
  30. dest: "{{ matrix_backup_borg_config_path }}/sshkey"
  31. owner: "{{ matrix_user_username }}"
  32. group: "{{ matrix_user_groupname }}"
  33. mode: 0600
  34. - name: Ensure borg image is pulled
  35. docker_image:
  36. name: "{{ matrix_backup_borg_docker_image }}"
  37. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  38. force_source: "{{ matrix_backup_borg_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  39. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_backup_borg_docker_image_force_pull }}"
  40. when: "not matrix_backup_borg_container_image_self_build|bool"
  41. register: result
  42. retries: "{{ matrix_container_retries_count }}"
  43. delay: "{{ matrix_container_retries_delay }}"
  44. until: result is not failed
  45. - name: Ensure borg repository is present on self-build
  46. git:
  47. repo: "{{ matrix_backup_borg_docker_repo }}"
  48. dest: "{{ matrix_backup_borg_docker_src_files_path }}"
  49. force: "yes"
  50. register: matrix_backup_borg_git_pull_results
  51. when: "matrix_backup_borg_container_image_self_build|bool"
  52. - name: Ensure borg image is built
  53. docker_image:
  54. name: "{{ matrix_backup_borg_docker_image }}"
  55. source: build
  56. force_source: "{{ matrix_backup_borg_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  57. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mailer_git_pull_results.changed }}"
  58. build:
  59. dockerfile: Dockerfile
  60. path: "{{ matrix_backup_borg_docker_src_files_path }}"
  61. pull: true
  62. when: "matrix_backup_borg_container_image_self_build|bool"
  63. - name: Ensure matrix-backup-borg.service installed
  64. template:
  65. src: "{{ role_path }}/templates/systemd/matrix-backup-borg.service.j2"
  66. dest: "{{ matrix_systemd_path }}/matrix-backup-borg.service"
  67. mode: 0644
  68. register: matrix_backup_borg_systemd_service_result
  69. - name: Ensure matrix-backup-borg.timer installed
  70. template:
  71. src: "{{ role_path }}/templates/systemd/matrix-backup-borg.timer.j2"
  72. dest: "{{ matrix_systemd_path }}/matrix-backup-borg.timer"
  73. mode: 0644
  74. register: matrix_backup_borg_systemd_timer_result
  75. - name: Ensure systemd reloaded after matrix-backup-borg.service installation
  76. service:
  77. daemon_reload: true
  78. when: "matrix_backup_borg_systemd_service_result.changed|bool"
  79. - name: Ensure matrix-backup-borg.service enabled
  80. service:
  81. enabled: true
  82. name: matrix-backup-borg.service
  83. - name: Ensure matrix-backup-borg.timer enabled
  84. service:
  85. enabled: true
  86. name: matrix-backup-borg.timer