Matrix Docker Ansible eploy
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

198 řádky
7.5 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: Inject warning if on an old version of Postgres
  17. set_fact:
  18. matrix_playbook_runtime_results: |
  19. {{
  20. matrix_playbook_runtime_results|default([])
  21. +
  22. [
  23. "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"
  24. ]
  25. }}
  26. when: "matrix_postgres_enabled|bool and matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest"
  27. # Even if we don't run the internal server, we still need this for running the CLI
  28. - name: Ensure postgres Docker image is pulled
  29. docker_image:
  30. name: "{{ matrix_postgres_docker_image_to_use }}"
  31. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  32. force_source: "{{ matrix_postgres_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  33. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_postgres_docker_image_force_pull }}"
  34. when: matrix_postgres_enabled|bool
  35. - name: Ensure Postgres paths exist
  36. file:
  37. path: "{{ item }}"
  38. state: directory
  39. mode: 0700
  40. owner: "{{ matrix_user_username }}"
  41. group: "{{ matrix_user_groupname }}"
  42. with_items:
  43. - "{{ matrix_postgres_base_path }}"
  44. - "{{ matrix_postgres_data_path }}"
  45. when: matrix_postgres_enabled|bool
  46. # We do this as a separate task, because:
  47. # - 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)
  48. # - we need to do it without `mode`, or we risk making certain `.conf` and other files's executable bit to flip to true
  49. - name: Ensure Postgres data path ownership is correct
  50. file:
  51. path: "{{ matrix_postgres_data_path }}"
  52. state: directory
  53. owner: "{{ matrix_user_username }}"
  54. group: "{{ matrix_user_groupname }}"
  55. recurse: yes
  56. when: matrix_postgres_enabled|bool
  57. - name: Ensure Postgres environment variables file created
  58. template:
  59. src: "{{ role_path }}/templates/{{ item }}.j2"
  60. dest: "{{ matrix_postgres_base_path }}/{{ item }}"
  61. mode: 0640
  62. with_items:
  63. - "env-postgres-psql"
  64. - "env-postgres-server"
  65. when: matrix_postgres_enabled|bool
  66. - name: Ensure matrix-postgres-cli script created
  67. template:
  68. src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli.j2"
  69. dest: "{{ matrix_local_bin_path }}/matrix-postgres-cli"
  70. mode: 0755
  71. when: matrix_postgres_enabled|bool
  72. - name: Ensure matrix-change-user-admin-status script created
  73. template:
  74. src: "{{ role_path }}/templates/usr-local-bin/matrix-change-user-admin-status.j2"
  75. dest: "{{ matrix_local_bin_path }}/matrix-change-user-admin-status"
  76. mode: 0755
  77. when: matrix_postgres_enabled|bool
  78. - name: (Migration) Ensure old matrix-make-user-admin script deleted
  79. file:
  80. path: "{{ matrix_local_bin_path }}/matrix-make-user-admin"
  81. state: absent
  82. when: matrix_postgres_enabled|bool
  83. - name: Ensure matrix-postgres-update-user-password-hash script created
  84. template:
  85. src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-update-user-password-hash.j2"
  86. dest: "{{ matrix_local_bin_path }}/matrix-postgres-update-user-password-hash"
  87. mode: 0755
  88. when: matrix_postgres_enabled|bool
  89. - name: Ensure matrix-postgres.service installed
  90. template:
  91. src: "{{ role_path }}/templates/systemd/matrix-postgres.service.j2"
  92. dest: "{{ matrix_systemd_path }}/matrix-postgres.service"
  93. mode: 0644
  94. register: matrix_postgres_systemd_service_result
  95. when: matrix_postgres_enabled|bool
  96. - name: Ensure systemd reloaded after matrix-postgres.service installation
  97. service:
  98. daemon_reload: yes
  99. when: "matrix_postgres_enabled|bool and matrix_postgres_systemd_service_result.changed"
  100. - include_tasks:
  101. file: "{{ role_path }}/tasks/util/create_additional_databases.yml"
  102. apply:
  103. tags:
  104. - always
  105. when: "matrix_postgres_enabled|bool and matrix_postgres_additional_databases|length > 0"
  106. - name: Check existence of matrix-postgres backup data path
  107. stat:
  108. path: "{{ matrix_postgres_data_path }}-auto-upgrade-backup"
  109. register: matrix_postgres_data_backup_path_stat
  110. when: "matrix_postgres_enabled|bool"
  111. - name: Inject warning if backup data remains
  112. set_fact:
  113. matrix_playbook_runtime_results: |
  114. {{
  115. matrix_playbook_runtime_results|default([])
  116. +
  117. [
  118. "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."
  119. ]
  120. }}
  121. when: "matrix_postgres_enabled|bool and matrix_postgres_data_backup_path_stat.stat.exists"
  122. #
  123. # Tasks related to getting rid of the internal postgres server (if it was previously enabled)
  124. #
  125. - name: Check existence of matrix-postgres service
  126. stat:
  127. path: "{{ matrix_systemd_path }}/matrix-postgres.service"
  128. register: matrix_postgres_service_stat
  129. when: "not matrix_postgres_enabled|bool"
  130. - name: Ensure matrix-postgres is stopped
  131. service:
  132. name: matrix-postgres
  133. state: stopped
  134. daemon_reload: yes
  135. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  136. - name: Ensure matrix-postgres.service doesn't exist
  137. file:
  138. path: "{{ matrix_systemd_path }}/matrix-postgres.service"
  139. state: absent
  140. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  141. - name: Ensure systemd reloaded after matrix-postgres.service removal
  142. service:
  143. daemon_reload: yes
  144. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  145. - name: Check existence of matrix-postgres local data path
  146. stat:
  147. path: "{{ matrix_postgres_data_path }}"
  148. register: matrix_postgres_data_path_stat
  149. when: "not matrix_postgres_enabled|bool"
  150. # We just want to notify the user. Deleting data is too destructive.
  151. - name: Inject warning if matrix-postgres local data remains
  152. set_fact:
  153. matrix_playbook_runtime_results: |
  154. {{
  155. matrix_playbook_runtime_results|default([])
  156. +
  157. [
  158. "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."
  159. ]
  160. }}
  161. when: "not matrix_postgres_enabled|bool and matrix_postgres_data_path_stat.stat.exists"
  162. - name: Remove Postgres scripts
  163. file:
  164. path: "{{ matrix_local_bin_path }}/{{ item }}"
  165. state: absent
  166. with_items:
  167. - matrix-postgres-cli
  168. - matrix-change-user-admin-status
  169. - matrix-postgres-update-user-password-hash
  170. when: "not matrix_postgres_enabled|bool"