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

79 строки
2.9 KiB

  1. # SPDX-FileCopyrightText: 2024 MDAD Team and contributors
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - name: Fail if Postgres not enabled
  6. ansible.builtin.fail:
  7. msg: "Postgres via ansible-role-postgres role is not enabled (`postgres_enabled`). Cannot migrate."
  8. when: "not postgres_enabled | bool"
  9. # Defaults
  10. - name: Set postgres_start_wait_time, if not provided
  11. ansible.builtin.set_fact:
  12. postgres_start_wait_time: 15
  13. when: "postgres_start_wait_time | default('') == ''"
  14. # Actual import work
  15. - name: Ensure Postgres is started
  16. ansible.builtin.service:
  17. name: "{{ postgres_identifier }}"
  18. state: started
  19. daemon_reload: true
  20. register: postgres_service_start_result
  21. - name: Wait a bit, so that Postgres can start
  22. ansible.builtin.wait_for:
  23. timeout: "{{ postgres_start_wait_time }}"
  24. delegate_to: 127.0.0.1
  25. become: false
  26. when: "postgres_service_start_result.changed | bool"
  27. - name: Ensure matrix-appservice-slack is stopped
  28. ansible.builtin.service:
  29. name: matrix-appservice-slack
  30. state: stopped
  31. - name: Import appservice-slack NeDB database into Postgres
  32. ansible.builtin.command:
  33. cmd: >-
  34. {{ devture_systemd_docker_base_host_command_docker }} run
  35. --rm
  36. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  37. --cap-drop=ALL
  38. {% if matrix_appservice_slack_database_container_network %}
  39. --network={{ matrix_appservice_irc_database_container_network }}
  40. {% endif %}
  41. --mount type=bind,src={{ matrix_appservice_slack_data_path }},dst=/data
  42. --entrypoint=/bin/sh
  43. {{ matrix_appservice_slack_docker_image }}
  44. -c
  45. '/usr/local/bin/node /usr/src/app/lib/scripts/migrateToPostgres.js --dbdir /data --connectionString {{ matrix_appservice_slack_database_connection_string }}'
  46. register: matrix_appservice_slack_import_nedb_to_postgres_result
  47. changed_when: matrix_appservice_slack_import_nedb_to_postgres_result.rc == 0
  48. - name: Archive NeDB database files
  49. ansible.builtin.command:
  50. cmd: "mv {{ matrix_appservice_slack_data_path }}/{{ item }} {{ matrix_appservice_slack_data_path }}/{{ item }}.backup"
  51. register: matrix_appservice_slack_import_nedb_to_postgres_move_result
  52. changed_when: matrix_appservice_slack_import_nedb_to_postgres_move_result.rc == 0
  53. with_items:
  54. - teams.db
  55. - room-store.db
  56. - user-store.db
  57. - event-store.db
  58. - name: Inject result
  59. ansible.builtin.set_fact:
  60. devture_playbook_runtime_messages_list: |
  61. {{
  62. devture_playbook_runtime_messages_list | default([])
  63. +
  64. [
  65. "Note: Your appservice-slack database files have been imported into Postgres. The original database files have been moved from `{{ matrix_appservice_slack_data_path }}/*.db` to `{{ matrix_appservice_slack_data_path }}/*.db.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete these files."
  66. ]
  67. }}