Matrix Docker Ansible eploy
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

144 satır
6.8 KiB

  1. # SPDX-FileCopyrightText: 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2025 Suguru Hirahara
  3. #
  4. # SPDX-License-Identifier: AGPL-3.0-or-later
  5. ---
  6. - ansible.builtin.set_fact:
  7. matrix_authentication_service_syn2mas_dry_run: "{{ matrix_authentication_service_syn2mas_dry_run | bool }}"
  8. - name: Abort, if not using Synapse
  9. when: not matrix_synapse_enabled | bool
  10. ansible.builtin.fail:
  11. msg: |-
  12. You can only use syn2mas to migrate from Synapse to Matrix Authentication Service.
  13. Other homeserver implementations are not supported.
  14. - name: Fail if required matrix-authentication-service syn2mas settings not defined
  15. ansible.builtin.fail:
  16. msg: >-
  17. You need to define a required configuration setting (`{{ item.name }}`).
  18. when: "item.when | bool and vars[item.name] | length == 0"
  19. with_items:
  20. - {'name': 'matrix_authentication_service_syn2mas_synapse_homeserver_config_path', when: true}
  21. - name: Check if Synapse homeserver config file exists
  22. ansible.builtin.stat:
  23. path: "{{ matrix_authentication_service_syn2mas_synapse_homeserver_config_path }}"
  24. register: matrix_authentication_service_syn2mas_synapse_config_stat
  25. - name: Fail if Synapse homeserver config file does not exist
  26. ansible.builtin.fail:
  27. msg: "The Synapse homeserver config file does not exist at the specified path: {{ matrix_authentication_service_syn2mas_synapse_homeserver_config_path }}"
  28. when: not matrix_authentication_service_syn2mas_synapse_config_stat.stat.exists
  29. - name: Ensure Matrix Authentication Service syn2mas container image is pulled
  30. community.docker.docker_image:
  31. name: "{{ matrix_authentication_service_syn2mas_container_image }}"
  32. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  33. force_source: "{{ matrix_authentication_service_syn2mas_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  34. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_authentication_service_syn2mas_container_image_force_pull }}"
  35. when: "not matrix_authentication_service_syn2mas_container_image_self_build | bool"
  36. register: result
  37. retries: "{{ devture_playbook_help_container_retries_count }}"
  38. delay: "{{ devture_playbook_help_container_retries_delay }}"
  39. until: result is not failed
  40. - when: "matrix_authentication_service_syn2mas_container_image_self_build | bool"
  41. block:
  42. - name: Ensure Matrix Authentication Service repository is present on self-build
  43. ansible.builtin.git:
  44. repo: "{{ matrix_authentication_service_container_repo }}"
  45. version: "{{ matrix_authentication_service_container_repo_version }}"
  46. dest: "{{ matrix_authentication_service_container_src_files_path }}"
  47. force: "yes"
  48. become: true
  49. become_user: "{{ matrix_user_name }}"
  50. register: matrix_authentication_service_git_pull_results
  51. - name: Ensure Matrix Authentication Service syn2mas container image is built
  52. ansible.builtin.command:
  53. cmd: |-
  54. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  55. --tag={{ matrix_authentication_service_syn2mas_container_image }}
  56. --file={{ matrix_authentication_service_container_src_files_path }}/tools/syn2mas/Dockerfile
  57. {{ matrix_authentication_service_container_src_files_path }}/tools/syn2mas
  58. changed_when: true
  59. - name: Ensure Synapse is stopped
  60. when: not matrix_authentication_service_syn2mas_dry_run | bool
  61. ansible.builtin.service:
  62. name: matrix-synapse
  63. state: stopped
  64. daemon_reload: true
  65. register: matrix_authentication_service_synapse_ensure_stopped_result
  66. # We probably don't necessarily need to stop this, because:
  67. # - the upstream docs don't say we should.
  68. # - while a migration is in progress (see `matrix_authentication_service_migration_in_progress`),
  69. # we don't even add compatibility layer labels, so MAS would not be used anyway.
  70. #
  71. # Still, it's probably safer to stop it anyway.
  72. - name: Ensure Matrix Authentication Service is stopped
  73. ansible.builtin.service:
  74. name: matrix-authentication-service
  75. state: stopped
  76. register: matrix_authentication_service_mas_ensure_stopped_result
  77. - name: Generate syn2mas migration command
  78. ansible.builtin.set_fact:
  79. matrix_authentication_service_syn2mas_migration_command: >-
  80. {{ devture_systemd_docker_base_host_command_docker }} run
  81. --rm
  82. --name=matrix-authentication-service-syn2mas
  83. --log-driver=none
  84. --user={{ matrix_authentication_service_uid }}:{{ matrix_authentication_service_gid }}
  85. --cap-drop=ALL
  86. --network={{ matrix_authentication_service_syn2mas_container_network }}
  87. --mount type=bind,src={{ matrix_authentication_service_syn2mas_synapse_homeserver_config_path }},dst=/homeserver.yaml,ro
  88. --mount type=bind,src={{ matrix_authentication_service_config_path }}/config.yaml,dst=/mas-config.yaml,ro
  89. {{ matrix_authentication_service_syn2mas_container_image }}
  90. --command=migrate
  91. --synapseConfigFile=/homeserver.yaml
  92. --masConfigFile=/mas-config.yaml
  93. {{ matrix_authentication_service_syn2mas_process_extra_arguments | join(' ') }}
  94. {% if matrix_authentication_service_syn2mas_dry_run | bool %}--dryRun{% endif %}
  95. tags:
  96. - skip_ansible_lint
  97. # This is a hack.
  98. # See: https://ansibledaily.com/print-to-standard-output-without-escaping/
  99. #
  100. # We want to run `debug: msg=".."`, but that dumps it as JSON and escapes double quotes within it,
  101. # which ruins the command (`matrix_authentication_service_syn2mas_migration_command`).
  102. - name: Note about syn2mas migration
  103. ansible.builtin.set_fact:
  104. dummy: true
  105. with_items:
  106. - >-
  107. Running syn2mas migration using the following command: `{{ matrix_authentication_service_syn2mas_migration_command }}`.
  108. If this crashes, you can stop Synapse (`systemctl stop matrix-synapse`) and run the command manually.
  109. - name: Perform syn2mas migration
  110. ansible.builtin.command:
  111. cmd: "{{ matrix_authentication_service_syn2mas_migration_command }}"
  112. register: matrix_authentication_service_syn2mas_migration_command_result
  113. changed_when: matrix_authentication_service_syn2mas_migration_command_result.rc == 0
  114. - name: Print syn2mas migration command result
  115. ansible.builtin.debug:
  116. var: matrix_authentication_service_syn2mas_migration_command_result
  117. - name: Ensure Synapse is started (if it previously was)
  118. when: "not matrix_authentication_service_syn2mas_dry_run and matrix_authentication_service_synapse_ensure_stopped_result.changed"
  119. ansible.builtin.service:
  120. name: matrix-synapse
  121. state: started
  122. - name: Ensure Matrix Authentication Service is started (if it previously was)
  123. when: "not matrix_authentication_service_syn2mas_dry_run and matrix_authentication_service_mas_ensure_stopped_result.changed"
  124. ansible.builtin.service:
  125. name: matrix-authentication-service
  126. state: started