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

111 строки
4.5 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. owner: "{{ matrix_user_username }}"
  40. group: "{{ matrix_user_groupname }}"
  41. mode: 0640
  42. with_items:
  43. - "env-postgres-backup"
  44. when: matrix_postgres_backup_enabled|bool
  45. - name: Ensure matrix-postgres-backup.service installed
  46. template:
  47. src: "{{ role_path }}/templates/systemd/matrix-postgres-backup.service.j2"
  48. dest: "{{ matrix_systemd_path }}/matrix-postgres-backup.service"
  49. mode: 0644
  50. register: matrix_postgres_backup_systemd_service_result
  51. when: matrix_postgres_backup_enabled|bool
  52. - name: Ensure systemd reloaded after matrix-postgres-backup.service installation
  53. service:
  54. daemon_reload: true
  55. when: "matrix_postgres_backup_enabled|bool and matrix_postgres_backup_systemd_service_result.changed"
  56. #
  57. # Tasks related to getting rid of the internal postgres backup server (if it was previously enabled)
  58. #
  59. - name: Check existence of matrix-postgres-backup service
  60. stat:
  61. path: "{{ matrix_systemd_path }}/matrix-postgres-backup.service"
  62. register: matrix_postgres_backup_service_stat
  63. when: "not matrix_postgres_backup_enabled|bool"
  64. - name: Ensure matrix-postgres-backup is stopped
  65. service:
  66. name: matrix-postgres-backup
  67. state: stopped
  68. enabled: false
  69. daemon_reload: true
  70. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists"
  71. - name: Ensure matrix-postgres-backup.service doesn't exist
  72. file:
  73. path: "{{ matrix_systemd_path }}/matrix-postgres-backup.service"
  74. state: absent
  75. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists"
  76. - name: Ensure systemd reloaded after matrix-postgres-backup.service removal
  77. service:
  78. daemon_reload: true
  79. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists"
  80. - name: Check existence of matrix-postgres-backup backup path
  81. stat:
  82. path: "{{ matrix_postgres_backup_path }}"
  83. register: matrix_postgres_backup_path_stat
  84. when: "not matrix_postgres_backup_enabled|bool"
  85. # We just want to notify the user. Deleting data is too destructive.
  86. - name: Inject warning if matrix-postgres backup data remains
  87. set_fact:
  88. matrix_playbook_runtime_results: |
  89. {{
  90. matrix_playbook_runtime_results|default([])
  91. +
  92. [
  93. "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."
  94. ]
  95. }}
  96. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_path_stat.stat.exists"