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

77 строки
2.9 KiB

  1. ---
  2. - name: Fail if Postgres not enabled
  3. ansible.builtin.fail:
  4. msg: "Postgres via the com.devture.ansible.role.postgres role is not enabled (`devture_postgres_enabled`). Cannot migrate."
  5. when: "not devture_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 Postgres is started
  13. ansible.builtin.service:
  14. name: "{{ devture_postgres_identifier }}"
  15. state: started
  16. daemon_reload: true
  17. register: 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: postgres_service_start_result.changed | bool
  24. - name: Check existence of matrix-appservice-irc service
  25. ansible.builtin.stat:
  26. path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-irc.service"
  27. register: matrix_appservice_irc_service_stat
  28. - name: Ensure matrix-appservice-irc is stopped
  29. ansible.builtin.service:
  30. name: matrix-appservice-irc
  31. state: stopped
  32. when: "matrix_appservice_irc_service_stat.stat.exists"
  33. - name: Import appservice-irc NeDB database into Postgres
  34. ansible.builtin.command:
  35. cmd: >-
  36. {{ devture_systemd_docker_base_host_command_docker }} run
  37. --rm
  38. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  39. --cap-drop=ALL
  40. --network={{ matrix_docker_network }}
  41. --mount type=bind,src={{ matrix_appservice_irc_data_path }},dst=/data
  42. --entrypoint=/bin/sh
  43. {{ matrix_appservice_irc_docker_image }}
  44. -c
  45. '/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 }}'
  46. register: matrix_appservice_irc_import_nedb_to_postgres_result
  47. changed_when: matrix_appservice_irc_import_nedb_to_postgres_result.rc == 0
  48. - name: Archive NeDB database files
  49. ansible.builtin.command:
  50. cmd: "mv {{ matrix_appservice_irc_data_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}.backup"
  51. with_items:
  52. - rooms.db
  53. - users.db
  54. register: matrix_appservice_irc_import_nedb_to_postgres_move_result
  55. changed_when: matrix_appservice_irc_import_nedb_to_postgres_move_result.rc == 0
  56. - name: Inject result
  57. ansible.builtin.set_fact:
  58. devture_playbook_runtime_messages_list: |
  59. {{
  60. devture_playbook_runtime_messages_list | default([])
  61. +
  62. [
  63. "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."
  64. ]
  65. }}