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

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