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.
 
 

108 line
4.8 KiB

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