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

90 строки
3.1 KiB

  1. ---
  2. # Pre-checks
  3. - name: Fail if Postgres not enabled
  4. ansible.builtin.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. ansible.builtin.fail:
  9. msg: "The `server_path_homeserver_db` variable needs to be provided to this playbook, via --extra-vars"
  10. when: "server_path_homeserver_db is not defined or server_path_homeserver_db.startswith('<')"
  11. - name: Check if the provided SQLite homeserver.db file exists
  12. ansible.builtin.stat:
  13. path: "{{ server_path_homeserver_db }}"
  14. register: result_server_path_homeserver_db_stat
  15. - name: Fail if provided SQLite homeserver.db file doesn't exist
  16. ansible.builtin.fail:
  17. msg: "File cannot be found on the server at {{ server_path_homeserver_db }}"
  18. when: "not result_server_path_homeserver_db_stat.stat.exists"
  19. # Defaults
  20. - name: Set postgres_start_wait_time, if not provided
  21. ansible.builtin.set_fact:
  22. postgres_start_wait_time: 15
  23. when: "postgres_start_wait_time | default('') == ''"
  24. # Actual import work
  25. - name: Ensure matrix-postgres is stopped
  26. ansible.builtin.service:
  27. name: matrix-postgres
  28. state: stopped
  29. daemon_reload: true
  30. - name: Ensure postgres data is wiped out
  31. ansible.builtin.file:
  32. path: "{{ matrix_postgres_data_path }}"
  33. state: absent
  34. - name: Ensure postgres data path exists
  35. ansible.builtin.file:
  36. path: "{{ matrix_postgres_data_path }}"
  37. state: directory
  38. mode: 0700
  39. owner: "{{ matrix_user_username }}"
  40. group: "{{ matrix_user_groupname }}"
  41. - name: Ensure matrix-postgres is started
  42. ansible.builtin.service:
  43. name: matrix-postgres
  44. state: restarted
  45. daemon_reload: true
  46. - name: Wait a bit, so that Postgres can start
  47. ansible.builtin.wait_for:
  48. timeout: "{{ postgres_start_wait_time }}"
  49. delegate_to: 127.0.0.1
  50. become: false
  51. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  52. # a very recent version, which is not available for a lot of people yet.
  53. #
  54. # Also, some old `docker_container` versions were buggy and would leave containers behind
  55. # on failure, which we had to work around to allow retries (by re-running the playbook).
  56. - name: Import SQLite database into Postgres
  57. ansible.builtin.command:
  58. cmd: |
  59. docker run
  60. --rm
  61. --name=matrix-synapse-migrate
  62. --log-driver=none
  63. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  64. --cap-drop=ALL
  65. --network={{ matrix_docker_network }}
  66. --entrypoint=python
  67. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
  68. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/matrix-media-store-parent/media-store
  69. --mount type=bind,src={{ server_path_homeserver_db }},dst=/{{ server_path_homeserver_db | basename }}
  70. {{ matrix_synapse_docker_image_final }}
  71. /usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db | basename }} --postgres-config /data/homeserver.yaml
  72. register: matrix_postgres_import_synapse_sqlite_db_result
  73. changed_when: matrix_postgres_import_synapse_sqlite_db_result.rc == 0