Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

83 line
3.1 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: Check existence of matrix-appservice-irc service
  28. ansible.builtin.stat:
  29. path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-irc.service"
  30. register: matrix_appservice_irc_service_stat
  31. - name: Ensure matrix-appservice-irc is stopped
  32. ansible.builtin.service:
  33. name: matrix-appservice-irc
  34. state: stopped
  35. when: "matrix_appservice_irc_service_stat.stat.exists"
  36. - name: Import appservice-irc NeDB database into Postgres
  37. ansible.builtin.command:
  38. cmd: >-
  39. {{ devture_systemd_docker_base_host_command_docker }} run
  40. --rm
  41. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  42. --cap-drop=ALL
  43. {% if matrix_appservice_irc_database_container_network %}
  44. --network={{ matrix_appservice_irc_database_container_network }}
  45. {% endif %}
  46. --mount type=bind,src={{ matrix_appservice_irc_data_path }},dst=/data
  47. --entrypoint=/bin/sh
  48. {{ matrix_appservice_irc_docker_image }}
  49. -c
  50. '/usr/local/bin/node /app/lib/scripts/migrate-db-to-pgres.js --dbdir /data --privateKey /data/passkey.pem --connectionString {{ matrix_appservice_irc_database_connection_string }}'
  51. register: matrix_appservice_irc_import_nedb_to_postgres_result
  52. changed_when: matrix_appservice_irc_import_nedb_to_postgres_result.rc == 0
  53. - name: Archive NeDB database files
  54. ansible.builtin.command:
  55. cmd: "mv {{ matrix_appservice_irc_data_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}.backup"
  56. with_items:
  57. - rooms.db
  58. - users.db
  59. register: matrix_appservice_irc_import_nedb_to_postgres_move_result
  60. changed_when: matrix_appservice_irc_import_nedb_to_postgres_move_result.rc == 0
  61. - name: Inject result
  62. ansible.builtin.set_fact:
  63. devture_playbook_runtime_messages_list: |
  64. {{
  65. devture_playbook_runtime_messages_list | default([])
  66. +
  67. [
  68. "Note: Your appservice-irc database files have been imported into Postgres. The original database files have been moved from `{{ matrix_appservice_irc_data_path }}/*.db` to `{{ matrix_appservice_irc_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."
  69. ]
  70. }}