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

139 строки
6.6 KiB

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