Matrix Docker Ansible eploy
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

216 líneas
8.3 KiB

  1. ---
  2. #
  3. # Tasks related to setting up an internal postgres server
  4. #
  5. - import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml"
  6. when: matrix_postgres_enabled|bool
  7. - import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml"
  8. when: matrix_postgres_enabled|bool
  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. - set_fact:
  14. matrix_postgres_docker_image_to_use: "{{ matrix_postgres_docker_image_latest if matrix_postgres_detected_version_corresponding_docker_image == '' else matrix_postgres_detected_version_corresponding_docker_image }}"
  15. when: matrix_postgres_enabled|bool
  16. - name: Abort if on an unsupported Postgres version
  17. fail:
  18. msg: "You're on Postgres {{ matrix_postgres_detected_version }}, which is no longer supported. To upgrade, see docs/maintenance-postgres.md"
  19. when: "matrix_postgres_enabled|bool and matrix_postgres_detected_version.startswith('9.')"
  20. - name: Inject warning if on an old version of Postgres
  21. set_fact:
  22. matrix_playbook_runtime_results: |
  23. {{
  24. matrix_playbook_runtime_results|default([])
  25. +
  26. [
  27. "NOTE: Your setup is on an old Postgres version ({{ matrix_postgres_docker_image_to_use }}), while {{ matrix_postgres_docker_image_latest }} is supported. You can upgrade using --tags=upgrade-postgres"
  28. ]
  29. }}
  30. when: "matrix_postgres_enabled|bool and matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest"
  31. # Even if we don't run the internal server, we still need this for running the CLI
  32. - name: Ensure postgres Docker image is pulled
  33. docker_image:
  34. name: "{{ matrix_postgres_docker_image_to_use }}"
  35. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  36. force_source: "{{ matrix_postgres_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  37. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_postgres_docker_image_force_pull }}"
  38. when: matrix_postgres_enabled|bool
  39. register: result
  40. retries: "{{ matrix_container_retries_count }}"
  41. delay: "{{ matrix_container_retries_delay }}"
  42. until: result is not failed
  43. - name: Ensure Postgres paths exist
  44. file:
  45. path: "{{ item }}"
  46. state: directory
  47. mode: 0700
  48. owner: "{{ matrix_user_username }}"
  49. group: "{{ matrix_user_groupname }}"
  50. with_items:
  51. - "{{ matrix_postgres_base_path }}"
  52. - "{{ matrix_postgres_data_path }}"
  53. when: matrix_postgres_enabled|bool
  54. # We do this as a separate task, because:
  55. # - we'd like to do it for the data path only, not for the base path (which contains root-owned environment variable files we'd like to leave as-is)
  56. # - we need to do it without `mode`, or we risk making certain `.conf` and other files's executable bit to flip to true
  57. - name: Ensure Postgres data path ownership is correct
  58. file:
  59. path: "{{ matrix_postgres_data_path }}"
  60. state: directory
  61. owner: "{{ matrix_user_username }}"
  62. group: "{{ matrix_user_groupname }}"
  63. recurse: true
  64. when: matrix_postgres_enabled|bool
  65. - name: Ensure Postgres environment variables file created
  66. template:
  67. src: "{{ role_path }}/templates/{{ item }}.j2"
  68. dest: "{{ matrix_postgres_base_path }}/{{ item }}"
  69. owner: "{{ matrix_user_username }}"
  70. group: "{{ matrix_user_groupname }}"
  71. mode: 0640
  72. with_items:
  73. - "env-postgres-psql"
  74. - "env-postgres-server"
  75. when: matrix_postgres_enabled|bool
  76. - name: Ensure matrix-postgres-cli script created
  77. template:
  78. src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli.j2"
  79. dest: "{{ matrix_local_bin_path }}/matrix-postgres-cli"
  80. mode: 0755
  81. when: matrix_postgres_enabled|bool
  82. - name: Ensure matrix-postgres-cli-non-interactive script created
  83. template:
  84. src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli-non-interactive.j2"
  85. dest: "{{ matrix_local_bin_path }}/matrix-postgres-cli-non-interactive"
  86. mode: 0755
  87. when: matrix_postgres_enabled|bool
  88. - name: Ensure matrix-change-user-admin-status script created
  89. template:
  90. src: "{{ role_path }}/templates/usr-local-bin/matrix-change-user-admin-status.j2"
  91. dest: "{{ matrix_local_bin_path }}/matrix-change-user-admin-status"
  92. mode: 0755
  93. when: matrix_postgres_enabled|bool
  94. - name: (Migration) Ensure old matrix-make-user-admin script deleted
  95. file:
  96. path: "{{ matrix_local_bin_path }}/matrix-make-user-admin"
  97. state: absent
  98. when: matrix_postgres_enabled|bool
  99. - name: Ensure matrix-postgres-update-user-password-hash script created
  100. template:
  101. src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-update-user-password-hash.j2"
  102. dest: "{{ matrix_local_bin_path }}/matrix-postgres-update-user-password-hash"
  103. mode: 0755
  104. when: matrix_postgres_enabled|bool
  105. - name: Ensure matrix-postgres.service installed
  106. template:
  107. src: "{{ role_path }}/templates/systemd/matrix-postgres.service.j2"
  108. dest: "{{ matrix_systemd_path }}/matrix-postgres.service"
  109. mode: 0644
  110. register: matrix_postgres_systemd_service_result
  111. when: matrix_postgres_enabled|bool
  112. - name: Ensure systemd reloaded after matrix-postgres.service installation
  113. service:
  114. daemon_reload: true
  115. when: "matrix_postgres_enabled|bool and matrix_postgres_systemd_service_result.changed"
  116. - include_tasks:
  117. file: "{{ role_path }}/tasks/util/create_additional_databases.yml"
  118. apply:
  119. tags:
  120. - always
  121. when: "matrix_postgres_enabled|bool and matrix_postgres_additional_databases|length > 0"
  122. - name: Check existence of matrix-postgres backup data path
  123. stat:
  124. path: "{{ matrix_postgres_data_path }}-auto-upgrade-backup"
  125. register: matrix_postgres_data_backup_path_stat
  126. when: "matrix_postgres_enabled|bool"
  127. - name: Inject warning if backup data remains
  128. set_fact:
  129. matrix_playbook_runtime_results: |
  130. {{
  131. matrix_playbook_runtime_results|default([])
  132. +
  133. [
  134. "NOTE: You have some Postgres backup data in `{{ matrix_postgres_data_path }}-auto-upgrade-backup`, which was created during the last major Postgres update you ran. If your setup works well after this upgrade, feel free to delete this whole directory."
  135. ]
  136. }}
  137. when: "matrix_postgres_enabled|bool and matrix_postgres_data_backup_path_stat.stat.exists"
  138. #
  139. # Tasks related to getting rid of the internal postgres server (if it was previously enabled)
  140. #
  141. - name: Check existence of matrix-postgres service
  142. stat:
  143. path: "{{ matrix_systemd_path }}/matrix-postgres.service"
  144. register: matrix_postgres_service_stat
  145. when: "not matrix_postgres_enabled|bool"
  146. - name: Ensure matrix-postgres is stopped
  147. service:
  148. name: matrix-postgres
  149. state: stopped
  150. daemon_reload: true
  151. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  152. - name: Ensure matrix-postgres.service doesn't exist
  153. file:
  154. path: "{{ matrix_systemd_path }}/matrix-postgres.service"
  155. state: absent
  156. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  157. - name: Ensure systemd reloaded after matrix-postgres.service removal
  158. service:
  159. daemon_reload: true
  160. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  161. - name: Check existence of matrix-postgres local data path
  162. stat:
  163. path: "{{ matrix_postgres_data_path }}"
  164. register: matrix_postgres_data_path_stat
  165. when: "not matrix_postgres_enabled|bool"
  166. # We just want to notify the user. Deleting data is too destructive.
  167. - name: Inject warning if matrix-postgres local data remains
  168. set_fact:
  169. matrix_playbook_runtime_results: |
  170. {{
  171. matrix_playbook_runtime_results|default([])
  172. +
  173. [
  174. "NOTE: You are not using a local PostgreSQL database, but some old data remains from before in `{{ matrix_postgres_data_path }}`. Feel free to delete it."
  175. ]
  176. }}
  177. when: "not matrix_postgres_enabled|bool and matrix_postgres_data_path_stat.stat.exists"
  178. - name: Remove Postgres scripts
  179. file:
  180. path: "{{ matrix_local_bin_path }}/{{ item }}"
  181. state: absent
  182. with_items:
  183. - matrix-postgres-cli
  184. - matrix-change-user-admin-status
  185. - matrix-postgres-update-user-password-hash
  186. when: "not matrix_postgres_enabled|bool"