Matrix Docker Ansible eploy
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

113 wiersze
4.8 KiB

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