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.
 
 

118 líneas
4.8 KiB

  1. ---
  2. # Pre-checks
  3. - name: Fail if Postgres not enabled
  4. fail:
  5. msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import."
  6. when: "not matrix_postgres_enabled|bool"
  7. - name: Fail if playbook called incorrectly
  8. fail:
  9. msg: "The `nedb_database_path` variable needs to be provided to this playbook, via --extra-vars"
  10. when: "nedb_database_path is not defined or nedb_database_path.startswith('<')"
  11. - name: Check if the provided nedb database file exists
  12. stat:
  13. path: "{{ nedb_database_path }}"
  14. register: nedb_database_path_stat_result
  15. - name: Fail if provided SQLite database file doesn't exist
  16. fail:
  17. msg: "File cannot be found on the server at {{ nedb_database_path }}"
  18. when: "not nedb_database_path_stat_result.stat.exists"
  19. # We either expect `postgres_db_connection_string` specifying a full Postgres database connection string,
  20. # or `postgres_connection_string_variable_name`, specifying a name of a variable, which contains a valid connection string.
  21. - block:
  22. - name: Fail if postgres_connection_string_variable_name points to an undefined variable
  23. fail: msg="postgres_connection_string_variable_name is defined, but there is no variable with the name `{{ postgres_connection_string_variable_name }}`"
  24. when: "postgres_connection_string_variable_name not in vars"
  25. - name: Get Postgres connection string from variable
  26. set_fact:
  27. postgres_db_connection_string: "{{ lookup('vars', postgres_connection_string_variable_name) }}"
  28. when: 'postgres_connection_string_variable_name is defined'
  29. - name: Fail if playbook called incorrectly
  30. fail:
  31. msg: >-
  32. Either a `postgres_db_connection_string` variable or a `postgres_connection_string_variable_name` needs to be provided to this playbook, via `--extra-vars`.
  33. Example: `--extra-vars="postgres_db_connection_string=postgresql://username:password@localhost:<port>/database_name"` or `--extra-vars="postgres_connection_string_variable_name=matrix_appservice_discord_database_connString"`
  34. when: "postgres_db_connection_string is not defined or not postgres_db_connection_string.startswith('postgresql://')"
  35. # Defaults
  36. - name: Set postgres_start_wait_time, if not provided
  37. set_fact:
  38. postgres_start_wait_time: 15
  39. when: "postgres_start_wait_time|default('') == ''"
  40. # Actual import work
  41. - name: Ensure matrix-postgres is started
  42. service:
  43. name: matrix-postgres
  44. state: started
  45. daemon_reload: yes
  46. register: matrix_postgres_service_start_result
  47. - name: Wait a bit, so that Postgres can start
  48. wait_for:
  49. timeout: "{{ postgres_start_wait_time }}"
  50. delegate_to: 127.0.0.1
  51. become: false
  52. when: "matrix_postgres_service_start_result.changed|bool"
  53. # See https://github.com/matrix-org/matrix-appservice-irc/wiki/Migrating-from-NEdB-to-PostgreSQL
  54. - name: Import appservice_irc NeDB database from {{ sqlite_database_path }} into Postgres
  55. when: database == 'appservice_irc'
  56. command:
  57. cmd: >-
  58. {{ matrix_host_command_docker }} run
  59. --rm
  60. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  61. --cap-drop=ALL
  62. --network={{ matrix_docker_network }}
  63. --mount type=bind,src={{ matrix_appservice_irc_data_path }}:/data:ro
  64. --entrypoint=/bin/sh
  65. {{ matrix_appservice_irc_docker_image }}
  66. -c
  67. './scripts/migrate-db-to-pgres.sh -d /data -p passkey.pem -c {{ postgres_db_connection_string }}'
  68. # No migration.sh available, but found this:
  69. # https://github.com/matrix-org/matrix-appservice-slack/blob/develop/src/scripts/migrateToPostgres.ts
  70. # Usage should be similar to appservice_irc
  71. - name: Import appservice_slack NeDB database from {{ sqlite_database_path }} into Postgres
  72. when: database == 'appservice_slack'
  73. command:
  74. cmd: >-
  75. {{ matrix_host_command_docker }} run
  76. --rm
  77. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  78. --cap-drop=ALL
  79. --network={{ matrix_docker_network }}
  80. --mount type=bind,src={{ matrix_appservice_irc_data_path }}:/data:ro
  81. --entrypoint=/bin/sh
  82. {{ matrix_appservice_slack_docker_image }}
  83. -c
  84. 'node /lib/scripts/migrate-db-to-pgres.js -d /data -p passkey.pem -c {{ postgres_db_connection_string }}'
  85. - name: Archive NeDB database ({{ sqlite_database_path }} -> {{ sqlite_database_path }}.backup)
  86. command:
  87. cmd: "mv {{ sqlite_database_path }} {{ sqlite_database_path }}.backup"
  88. - name: Inject result
  89. set_fact:
  90. matrix_playbook_runtime_results: |
  91. {{
  92. matrix_playbook_runtime_results|default([])
  93. +
  94. [
  95. "NOTE: Your NeDB database file has been imported into Postgres. The original directory has been moved from `{{ nedb_database_path }}` to `{{ nedb_database_path }}.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete this file."
  96. ]
  97. }}