Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

113 строки
4.4 KiB

  1. ---
  2. - block:
  3. - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/detect_existing_postgres_version.yml"
  4. - name: Fail if detected Postgres version is unsupported
  5. fail:
  6. msg: "You cannot use borg backup with such an old version ({{ matrix_postgres_detected_version }}) of Postgres. Consider upgrading - link to docs for upgrading Postgres: docs/maintenance-postgres.md#upgrading-postgresql"
  7. when: "matrix_postgres_detected_version not in matrix_backup_borg_supported_postgres_versions"
  8. - name: Set the correct borg backup version to use
  9. set_fact:
  10. matrix_backup_borg_version: "{{ matrix_postgres_detected_version }}"
  11. when: matrix_backup_borg_postgresql_enabled|bool and matrix_backup_borg_version == ''
  12. - name: Ensure borg paths exist
  13. file:
  14. path: "{{ item.path }}"
  15. state: directory
  16. mode: 0750
  17. owner: "{{ matrix_user_username }}"
  18. group: "{{ matrix_user_groupname }}"
  19. with_items:
  20. - {path: "{{ matrix_backup_borg_config_path }}", when: true}
  21. - {path: "{{ matrix_backup_borg_docker_src_files_path }}", when: true}
  22. when: "item.when|bool"
  23. - name: Ensure borgmatic config is created
  24. copy:
  25. content: "{{ matrix_backup_borg_configuration|to_nice_yaml(indent=2, width=999999) }}"
  26. dest: "{{ matrix_backup_borg_config_path }}/config.yaml"
  27. owner: "{{ matrix_user_username }}"
  28. group: "{{ matrix_user_groupname }}"
  29. mode: 0640
  30. - name: Ensure borg passwd is created
  31. template:
  32. src: "{{ role_path }}/templates/passwd.j2"
  33. dest: "{{ matrix_backup_borg_config_path }}/passwd"
  34. owner: "{{ matrix_user_username }}"
  35. group: "{{ matrix_user_groupname }}"
  36. mode: 0640
  37. - name: Ensure borg ssh key is created
  38. template:
  39. src: "{{ role_path }}/templates/sshkey.j2"
  40. dest: "{{ matrix_backup_borg_config_path }}/sshkey"
  41. owner: "{{ matrix_user_username }}"
  42. group: "{{ matrix_user_groupname }}"
  43. mode: 0600
  44. - name: Ensure borg image is pulled
  45. docker_image:
  46. name: "{{ matrix_backup_borg_docker_image }}"
  47. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  48. force_source: "{{ matrix_backup_borg_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  49. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_backup_borg_docker_image_force_pull }}"
  50. when: "not matrix_backup_borg_container_image_self_build|bool"
  51. register: result
  52. retries: "{{ matrix_container_retries_count }}"
  53. delay: "{{ matrix_container_retries_delay }}"
  54. until: result is not failed
  55. - name: Ensure borg repository is present on self-build
  56. git:
  57. repo: "{{ matrix_backup_borg_docker_repo }}"
  58. dest: "{{ matrix_backup_borg_docker_src_files_path }}"
  59. force: "yes"
  60. become: true
  61. become_user: "{{ matrix_user_username }}"
  62. register: matrix_backup_borg_git_pull_results
  63. when: "matrix_backup_borg_container_image_self_build|bool"
  64. - name: Ensure borg image is built
  65. docker_image:
  66. name: "{{ matrix_backup_borg_docker_image }}"
  67. source: build
  68. force_source: "{{ matrix_backup_borg_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  69. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mailer_git_pull_results.changed }}"
  70. build:
  71. dockerfile: Dockerfile
  72. path: "{{ matrix_backup_borg_docker_src_files_path }}"
  73. pull: true
  74. when: "matrix_backup_borg_container_image_self_build|bool"
  75. - name: Ensure matrix-backup-borg.service installed
  76. template:
  77. src: "{{ role_path }}/templates/systemd/matrix-backup-borg.service.j2"
  78. dest: "{{ matrix_systemd_path }}/matrix-backup-borg.service"
  79. mode: 0644
  80. register: matrix_backup_borg_systemd_service_result
  81. - name: Ensure matrix-backup-borg.timer installed
  82. template:
  83. src: "{{ role_path }}/templates/systemd/matrix-backup-borg.timer.j2"
  84. dest: "{{ matrix_systemd_path }}/matrix-backup-borg.timer"
  85. mode: 0644
  86. register: matrix_backup_borg_systemd_timer_result
  87. - name: Ensure systemd reloaded after matrix-backup-borg.service installation
  88. service:
  89. daemon_reload: true
  90. when: "matrix_backup_borg_systemd_service_result.changed|bool"
  91. - name: Ensure matrix-backup-borg.service enabled
  92. service:
  93. enabled: true
  94. name: matrix-backup-borg.service
  95. - name: Ensure matrix-backup-borg.timer enabled
  96. service:
  97. enabled: true
  98. name: matrix-backup-borg.timer