Matrix Docker Ansible eploy
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 

87 rader
2.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 `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. 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. 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. 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. service:
  27. name: matrix-postgres
  28. state: stopped
  29. daemon_reload: yes
  30. - name: Ensure postgres data is wiped out
  31. file:
  32. path: "{{ matrix_postgres_data_path }}"
  33. state: absent
  34. - name: Ensure postgres data path exists
  35. 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. service:
  43. name: matrix-postgres
  44. state: restarted
  45. daemon_reload: yes
  46. - name: Wait a bit, so that Postgres can start
  47. 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. command: |
  58. docker run
  59. --rm
  60. --name=matrix-synapse-migrate
  61. --log-driver=none
  62. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  63. --cap-drop=ALL
  64. --network={{ matrix_docker_network }}
  65. --entrypoint=python
  66. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
  67. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/matrix-media-store-parent/media-store
  68. --mount type=bind,src={{ server_path_homeserver_db }},dst=/{{ server_path_homeserver_db|basename }}
  69. {{ matrix_synapse_docker_image }}
  70. /usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db|basename }} --postgres-config /data/homeserver.yaml