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

109 строки
4.4 KiB

  1. ---
  2. #
  3. # Tasks related to setting up an internal postgres server
  4. #
  5. - import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml"
  6. when: 'matrix_postgres_backup_enabled|bool and matrix_postgres_backup_postgres_data_path != ""'
  7. # If we have found an existing version (installed from before), we use its corresponding Docker image.
  8. # If not, we install using the latest Postgres.
  9. #
  10. # Upgrading is supposed to be performed separately and explicitly (see `upgrade_postgres.yml`).
  11. - set_fact:
  12. matrix_postgres_backup_docker_image_to_use: "{{ matrix_postgres_backup_docker_image_latest if matrix_postgres_backup_detected_version_corresponding_docker_image|default('') == '' else matrix_postgres_backup_detected_version_corresponding_docker_image }}"
  13. when: matrix_postgres_backup_enabled|bool
  14. - name: Ensure postgres backup Docker image is pulled
  15. docker_image:
  16. name: "{{ matrix_postgres_backup_docker_image_to_use }}"
  17. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  18. force_source: "{{ matrix_postgres_backup_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  19. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_postgres_backup_docker_image_force_pull }}"
  20. when: matrix_postgres_backup_enabled|bool
  21. register: result
  22. retries: "{{ matrix_container_retries_count }}"
  23. delay: "{{ matrix_container_retries_delay }}"
  24. until: result is not failed
  25. - name: Ensure Postgres backup paths exist
  26. file:
  27. path: "{{ item }}"
  28. state: directory
  29. mode: 0700
  30. owner: "{{ matrix_user_username }}"
  31. group: "{{ matrix_user_groupname }}"
  32. with_items:
  33. - "{{ matrix_postgres_backup_path }}"
  34. when: matrix_postgres_backup_enabled|bool
  35. - name: Ensure Postgres environment variables file created
  36. template:
  37. src: "{{ role_path }}/templates/{{ item }}.j2"
  38. dest: "{{ matrix_postgres_backup_path }}/{{ item }}"
  39. mode: 0640
  40. with_items:
  41. - "env-postgres-backup"
  42. when: matrix_postgres_backup_enabled|bool
  43. - name: Ensure matrix-postgres-backup.service installed
  44. template:
  45. src: "{{ role_path }}/templates/systemd/matrix-postgres-backup.service.j2"
  46. dest: "{{ matrix_systemd_path }}/matrix-postgres-backup.service"
  47. mode: 0644
  48. register: matrix_postgres_backup_systemd_service_result
  49. when: matrix_postgres_backup_enabled|bool
  50. - name: Ensure systemd reloaded after matrix-postgres-backup.service installation
  51. service:
  52. daemon_reload: true
  53. when: "matrix_postgres_backup_enabled|bool and matrix_postgres_backup_systemd_service_result.changed"
  54. #
  55. # Tasks related to getting rid of the internal postgres backup server (if it was previously enabled)
  56. #
  57. - name: Check existence of matrix-postgres-backup service
  58. stat:
  59. path: "{{ matrix_systemd_path }}/matrix-postgres-backup.service"
  60. register: matrix_postgres_backup_service_stat
  61. when: "not matrix_postgres_backup_enabled|bool"
  62. - name: Ensure matrix-postgres-backup is stopped
  63. service:
  64. name: matrix-postgres-backup
  65. state: stopped
  66. enabled: false
  67. daemon_reload: true
  68. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists"
  69. - name: Ensure matrix-postgres-backup.service doesn't exist
  70. file:
  71. path: "{{ matrix_systemd_path }}/matrix-postgres-backup.service"
  72. state: absent
  73. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists"
  74. - name: Ensure systemd reloaded after matrix-postgres-backup.service removal
  75. service:
  76. daemon_reload: true
  77. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists"
  78. - name: Check existence of matrix-postgres-backup backup path
  79. stat:
  80. path: "{{ matrix_postgres_backup_path }}"
  81. register: matrix_postgres_backup_path_stat
  82. when: "not matrix_postgres_backup_enabled|bool"
  83. # We just want to notify the user. Deleting data is too destructive.
  84. - name: Inject warning if matrix-postgres backup data remains
  85. set_fact:
  86. matrix_playbook_runtime_results: |
  87. {{
  88. matrix_playbook_runtime_results|default([])
  89. +
  90. [
  91. "NOTE: You are not using the local backup service to backup the PostgreSQL database, but some old data remains from before in `{{ matrix_postgres_backup_path }}`. Feel free to delete it."
  92. ]
  93. }}
  94. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_path_stat.stat.exists"