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

104 строки
4.2 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_enabled|bool
  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 == '' 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. - name: Ensure Postgres backup paths exist
  22. file:
  23. path: "{{ item }}"
  24. state: directory
  25. mode: 0700
  26. owner: "{{ matrix_user_username }}"
  27. group: "{{ matrix_user_groupname }}"
  28. with_items:
  29. - "{{ matrix_postgres_backup_path }}"
  30. when: matrix_postgres_backup_enabled|bool
  31. - name: Ensure Postgres environment variables file created
  32. template:
  33. src: "{{ role_path }}/templates/{{ item }}.j2"
  34. dest: "{{ matrix_postgres_backup_path }}/{{ item }}"
  35. mode: 0640
  36. with_items:
  37. - "env-postgres-backup"
  38. when: matrix_postgres_backup_enabled|bool
  39. - name: Ensure matrix-postgres-backup.service installed
  40. template:
  41. src: "{{ role_path }}/templates/systemd/matrix-postgres-backup.service.j2"
  42. dest: "{{ matrix_systemd_path }}/matrix-postgres-backup.service"
  43. mode: 0644
  44. register: matrix_postgres_backup_systemd_service_result
  45. when: matrix_postgres_backup_enabled|bool
  46. - name: Ensure systemd reloaded after matrix-postgres-backup.service installation
  47. service:
  48. daemon_reload: yes
  49. when: "matrix_postgres_backup_enabled|bool and matrix_postgres_backup_systemd_service_result.changed"
  50. #
  51. # Tasks related to getting rid of the internal postgres backup server (if it was previously enabled)
  52. #
  53. - name: Check existence of matrix-postgres-backup service
  54. stat:
  55. path: "{{ matrix_systemd_path }}/matrix-postgres-backup.service"
  56. register: matrix_postgres_backup_service_stat
  57. when: "not matrix_postgres_backup_enabled|bool"
  58. - name: Ensure matrix-postgres-backup is stopped
  59. service:
  60. name: matrix-postgres-backup
  61. state: stopped
  62. daemon_reload: yes
  63. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists"
  64. - name: Ensure matrix-postgres-backup.service doesn't exist
  65. file:
  66. path: "{{ matrix_systemd_path }}/matrix-postgres-backup.service"
  67. state: absent
  68. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists"
  69. - name: Ensure systemd reloaded after matrix-postgres-backup.service removal
  70. service:
  71. daemon_reload: yes
  72. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists"
  73. - name: Check existence of matrix-postgres-backup backup path
  74. stat:
  75. path: "{{ matrix_postgres_backup_path }}"
  76. register: matrix_postgres_backup_path_stat
  77. when: "not matrix_postgres_backup_enabled|bool"
  78. # We just want to notify the user. Deleting data is too destructive.
  79. - name: Inject warning if matrix-postgres backup data remains
  80. set_fact:
  81. matrix_playbook_runtime_results: |
  82. {{
  83. matrix_playbook_runtime_results|default([])
  84. +
  85. [
  86. "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."
  87. ]
  88. }}
  89. when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_path_stat.stat.exists"