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ů.
 
 

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