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

114 строки
4.6 KiB

  1. ---
  2. - block:
  3. - ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/detect_existing_postgres_version.yml"
  4. - name: Fail if detected Postgres version is unsupported
  5. ansible.builtin.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. ansible.builtin.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. ansible.builtin.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. ansible.builtin.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. ansible.builtin.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. ansible.builtin.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. ansible.builtin.git:
  57. repo: "{{ matrix_backup_borg_docker_repo }}"
  58. version: "{{ matrix_backup_borg_docker_repo_version }}"
  59. dest: "{{ matrix_backup_borg_docker_src_files_path }}"
  60. force: "yes"
  61. become: true
  62. become_user: "{{ matrix_user_username }}"
  63. register: matrix_backup_borg_git_pull_results
  64. when: "matrix_backup_borg_container_image_self_build | bool"
  65. - name: Ensure borg image is built
  66. docker_image:
  67. name: "{{ matrix_backup_borg_docker_image }}"
  68. source: build
  69. force_source: "{{ matrix_backup_borg_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  70. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mailer_git_pull_results.changed }}"
  71. build:
  72. dockerfile: Dockerfile
  73. path: "{{ matrix_backup_borg_docker_src_files_path }}"
  74. pull: true
  75. when: "matrix_backup_borg_container_image_self_build | bool"
  76. - name: Ensure matrix-backup-borg.service installed
  77. ansible.builtin.template:
  78. src: "{{ role_path }}/templates/systemd/matrix-backup-borg.service.j2"
  79. dest: "{{ matrix_systemd_path }}/matrix-backup-borg.service"
  80. mode: 0644
  81. register: matrix_backup_borg_systemd_service_result
  82. - name: Ensure matrix-backup-borg.timer installed
  83. ansible.builtin.template:
  84. src: "{{ role_path }}/templates/systemd/matrix-backup-borg.timer.j2"
  85. dest: "{{ matrix_systemd_path }}/matrix-backup-borg.timer"
  86. mode: 0644
  87. register: matrix_backup_borg_systemd_timer_result
  88. - name: Ensure systemd reloaded after matrix-backup-borg.service installation
  89. ansible.builtin.service:
  90. daemon_reload: true
  91. when: "matrix_backup_borg_systemd_service_result.changed | bool"
  92. - name: Ensure matrix-backup-borg.service enabled
  93. ansible.builtin.service:
  94. enabled: true
  95. name: matrix-backup-borg.service
  96. - name: Ensure matrix-backup-borg.timer enabled
  97. ansible.builtin.service:
  98. enabled: true
  99. name: matrix-backup-borg.timer