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.
 
 

73 lines
2.6 KiB

  1. ---
  2. - name: Fail if Postgres not enabled
  3. ansible.builtin.fail:
  4. msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate."
  5. when: "not matrix_postgres_enabled | bool"
  6. # Defaults
  7. - name: Set postgres_start_wait_time, if not provided
  8. ansible.builtin.set_fact:
  9. postgres_start_wait_time: 15
  10. when: "postgres_start_wait_time | default('') == ''"
  11. # Actual import work
  12. - name: Ensure matrix-postgres is started
  13. ansible.builtin.service:
  14. name: matrix-postgres
  15. state: started
  16. daemon_reload: true
  17. register: matrix_postgres_service_start_result
  18. - name: Wait a bit, so that Postgres can start
  19. ansible.builtin.wait_for:
  20. timeout: "{{ postgres_start_wait_time }}"
  21. delegate_to: 127.0.0.1
  22. become: false
  23. when: "matrix_postgres_service_start_result.changed | bool"
  24. - name: Ensure matrix-appservice-slack is stopped
  25. ansible.builtin.service:
  26. name: matrix-appservice-slack
  27. state: stopped
  28. - name: Import appservice-slack NeDB database into Postgres
  29. ansible.builtin.command:
  30. cmd: >-
  31. {{ matrix_host_command_docker }} run
  32. --rm
  33. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  34. --cap-drop=ALL
  35. --network={{ matrix_docker_network }}
  36. --mount type=bind,src={{ matrix_appservice_slack_data_path }},dst=/data
  37. --entrypoint=/bin/sh
  38. {{ matrix_appservice_slack_docker_image }}
  39. -c
  40. '/usr/local/bin/node /usr/src/app/lib/scripts/migrateToPostgres.js --dbdir /data --connectionString {{ matrix_appservice_slack_database_connection_string }}'
  41. register: matrix_appservice_slack_import_nedb_to_postgres_result
  42. changed_when: matrix_appservice_slack_import_nedb_to_postgres_result.rc == 0
  43. - name: Archive NeDB database files
  44. ansible.builtin.command:
  45. cmd: "mv {{ matrix_appservice_slack_data_path }}/{{ item }} {{ matrix_appservice_slack_data_path }}/{{ item }}.backup"
  46. register: matrix_appservice_slack_import_nedb_to_postgres_move_result
  47. changed_when: matrix_appservice_slack_import_nedb_to_postgres_move_result.rc == 0
  48. with_items:
  49. - teams.db
  50. - room-store.db
  51. - user-store.db
  52. - event-store.db
  53. - name: Inject result
  54. ansible.builtin.set_fact:
  55. matrix_playbook_runtime_results: |
  56. {{
  57. matrix_playbook_runtime_results | default([])
  58. +
  59. [
  60. "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."
  61. ]
  62. }}