Matrix Docker Ansible eploy
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

86 líneas
3.2 KiB

  1. # SPDX-FileCopyrightText: 2020 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2021 Jez Cope
  3. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  4. # SPDX-FileCopyrightText: 2024 Suguru Hirahara
  5. #
  6. # SPDX-License-Identifier: AGPL-3.0-or-later
  7. ---
  8. - name: Fail if Postgres not enabled
  9. ansible.builtin.fail:
  10. msg: "Postgres via ansible-role-postgres role is not enabled (`postgres_enabled`). Cannot migrate."
  11. when: "not postgres_enabled | bool"
  12. # Defaults
  13. - name: Set postgres_start_wait_time, if not provided
  14. ansible.builtin.set_fact:
  15. postgres_start_wait_time: 15
  16. when: "postgres_start_wait_time | default('') == ''"
  17. # Actual import work
  18. - name: Ensure Postgres is started
  19. ansible.builtin.service:
  20. name: "{{ postgres_identifier }}"
  21. state: started
  22. daemon_reload: true
  23. register: postgres_service_start_result
  24. - name: Wait a bit, so that Postgres can start
  25. ansible.builtin.wait_for:
  26. timeout: "{{ postgres_start_wait_time }}"
  27. delegate_to: 127.0.0.1
  28. become: false
  29. when: postgres_service_start_result.changed | bool
  30. - name: Check existence of matrix-appservice-irc service
  31. ansible.builtin.stat:
  32. path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-irc.service"
  33. register: matrix_appservice_irc_service_stat
  34. - name: Ensure matrix-appservice-irc is stopped
  35. ansible.builtin.service:
  36. name: matrix-appservice-irc
  37. state: stopped
  38. when: "matrix_appservice_irc_service_stat.stat.exists"
  39. - name: Import appservice-irc NeDB database into Postgres
  40. ansible.builtin.command:
  41. cmd: >-
  42. {{ devture_systemd_docker_base_host_command_docker }} run
  43. --rm
  44. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  45. --cap-drop=ALL
  46. {% if matrix_appservice_irc_database_container_network %}
  47. --network={{ matrix_appservice_irc_database_container_network }}
  48. {% endif %}
  49. --mount type=bind,src={{ matrix_appservice_irc_data_path }},dst=/data
  50. --entrypoint=/bin/sh
  51. {{ matrix_appservice_irc_container_image }}
  52. -c
  53. '/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 }}'
  54. register: matrix_appservice_irc_import_nedb_to_postgres_result
  55. changed_when: matrix_appservice_irc_import_nedb_to_postgres_result.rc == 0
  56. - name: Archive NeDB database files
  57. ansible.builtin.command:
  58. cmd: "mv {{ matrix_appservice_irc_data_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}.backup"
  59. with_items:
  60. - rooms.db
  61. - users.db
  62. register: matrix_appservice_irc_import_nedb_to_postgres_move_result
  63. changed_when: matrix_appservice_irc_import_nedb_to_postgres_move_result.rc == 0
  64. - name: Inject result
  65. ansible.builtin.set_fact:
  66. devture_playbook_runtime_messages_list: |
  67. {{
  68. devture_playbook_runtime_messages_list | default([])
  69. +
  70. [
  71. "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."
  72. ]
  73. }}