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.
 
 

90 lines
2.7 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"
  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_username }}"
  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. # If the actual migration command (below) fails, it will leave a container behind.
  52. # Starting it again later will relaunch that one, which may or may not work.
  53. # To ensure we're starting from a clean state, ensure any such leftovers are removed.
  54. - name: Cleanup any old leftover migration container
  55. docker_container:
  56. name: matrix-synapse-migrate
  57. state: absent
  58. - name: Importing SQLite database into Postgres
  59. docker_container:
  60. name: matrix-synapse-migrate
  61. image: "{{ matrix_synapse_docker_image }}"
  62. detach: no
  63. cleanup: yes
  64. entrypoint: /usr/local/bin/python
  65. command: "/usr/local/bin/synapse_port_db --sqlite-database {{ server_path_homeserver_db }} --postgres-config /data/homeserver.yaml"
  66. user: "{{ matrix_user_uid }}:{{ matrix_user_gid }}"
  67. volumes:
  68. - "{{ matrix_synapse_config_dir_path }}:/data"
  69. - "{{ matrix_synapse_run_path }}:/matrix-run"
  70. - "{{ server_path_homeserver_db }}:/{{ server_path_homeserver_db }}:ro"
  71. networks:
  72. - name: "{{ matrix_docker_network }}"