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

152 строки
5.9 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: "/usr/local/bin/matrix-postgres-cli"
  63. mode: 0750
  64. when: matrix_postgres_enabled|bool
  65. - name: Ensure matrix-make-user-admin script created
  66. template:
  67. src: "{{ role_path }}/templates/usr-local-bin/matrix-make-user-admin.j2"
  68. dest: "/usr/local/bin/matrix-make-user-admin"
  69. mode: 0750
  70. when: matrix_postgres_enabled|bool
  71. - name: Ensure matrix-postgres-update-user-password-hash script created
  72. template:
  73. src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-update-user-password-hash.j2"
  74. dest: "/usr/local/bin/matrix-postgres-update-user-password-hash"
  75. mode: 0750
  76. when: matrix_postgres_enabled|bool
  77. - name: Ensure matrix-postgres.service installed
  78. template:
  79. src: "{{ role_path }}/templates/systemd/matrix-postgres.service.j2"
  80. dest: "/etc/systemd/system/matrix-postgres.service"
  81. mode: 0644
  82. register: matrix_postgres_systemd_service_result
  83. when: matrix_postgres_enabled|bool
  84. - name: Ensure systemd reloaded after matrix-postgres.service installation
  85. service:
  86. daemon_reload: yes
  87. when: "matrix_postgres_enabled|bool and matrix_postgres_systemd_service_result.changed"
  88. #
  89. # Tasks related to getting rid of the internal postgres server (if it was previously enabled)
  90. #
  91. - name: Check existence of matrix-postgres service
  92. stat:
  93. path: "/etc/systemd/system/matrix-postgres.service"
  94. register: matrix_postgres_service_stat
  95. when: "not matrix_postgres_enabled|bool"
  96. - name: Ensure matrix-postgres is stopped
  97. service:
  98. name: matrix-postgres
  99. state: stopped
  100. daemon_reload: yes
  101. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  102. - name: Ensure matrix-postgres.service doesn't exist
  103. file:
  104. path: "/etc/systemd/system/matrix-postgres.service"
  105. state: absent
  106. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  107. - name: Ensure systemd reloaded after matrix-postgres.service removal
  108. service:
  109. daemon_reload: yes
  110. when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
  111. - name: Check existence of matrix-postgres local data path
  112. stat:
  113. path: "{{ matrix_postgres_data_path }}"
  114. register: matrix_postgres_data_path_stat
  115. when: "not matrix_postgres_enabled|bool"
  116. # We just want to notify the user. Deleting data is too destructive.
  117. - name: Notify if matrix-postgres local data remains
  118. debug:
  119. 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."
  120. when: "not matrix_postgres_enabled|bool and matrix_postgres_data_path_stat.stat.exists"
  121. - name: Remove Postgres scripts
  122. file:
  123. path: "/usr/local/bin/{{ item }}"
  124. state: absent
  125. with_items:
  126. - matrix-postgres-cli
  127. - matrix-make-user-admin
  128. - matrix-postgres-update-user-password-hash
  129. when: "not matrix_postgres_enabled|bool"