Matrix Docker Ansible eploy
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

143 linhas
6.7 KiB

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