Matrix Docker Ansible eploy
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 

117 рядки
4.6 KiB

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