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

151 строка
6.3 KiB

  1. ---
  2. # This will throw a Permission Denied error if already mounted using fuse
  3. - name: Check Synapse media store path
  4. ansible.builtin.stat:
  5. path: "{{ matrix_synapse_media_store_path }}"
  6. register: local_path_media_store_stat
  7. ignore_errors: true
  8. # This is separate and conditional, to ensure we don't execute it
  9. # if the path already exists or we failed to check, because it's mounted using fuse.
  10. - name: Ensure Synapse media store path exists
  11. ansible.builtin.file:
  12. path: "{{ matrix_synapse_media_store_path }}"
  13. state: directory
  14. mode: 0750
  15. owner: "{{ matrix_user_username }}"
  16. group: "{{ matrix_user_groupname }}"
  17. when: "not local_path_media_store_stat.failed and not local_path_media_store_stat.stat.exists"
  18. - when: "matrix_synapse_container_image_self_build | bool"
  19. block:
  20. - name: Ensure Synapse repository is present on self-build
  21. ansible.builtin.git:
  22. repo: "{{ matrix_synapse_container_image_self_build_repo }}"
  23. dest: "{{ matrix_synapse_docker_src_files_path }}"
  24. version: "{{ matrix_synapse_docker_image.split(':')[1] }}"
  25. force: "yes"
  26. become: true
  27. become_user: "{{ matrix_user_username }}"
  28. register: matrix_synapse_git_pull_results
  29. - name: Check if Synapse Docker image exists
  30. ansible.builtin.command: "{{ matrix_host_command_docker }} images --quiet --filter 'reference={{ matrix_synapse_docker_image }}'"
  31. register: matrix_synapse_docker_image_check_result
  32. changed_when: false
  33. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  34. # because the latter does not support BuildKit.
  35. # See: https://github.com/ansible-collections/community.general/issues/514
  36. - name: Ensure Synapse Docker image is built
  37. ansible.builtin.shell:
  38. chdir: "{{ matrix_synapse_docker_src_files_path }}"
  39. cmd: |
  40. {{ matrix_host_command_docker }} build \
  41. -t "{{ matrix_synapse_docker_image }}" \
  42. -f docker/Dockerfile \
  43. .
  44. environment:
  45. DOCKER_BUILDKIT: 1
  46. when: "matrix_synapse_git_pull_results.changed | bool or matrix_synapse_docker_image_check_result.stdout == ''"
  47. - name: Ensure Synapse Docker image is pulled
  48. docker_image:
  49. name: "{{ matrix_synapse_docker_image }}"
  50. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  51. force_source: "{{ matrix_synapse_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  52. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_synapse_docker_image_force_pull }}"
  53. when: "not matrix_synapse_container_image_self_build"
  54. register: result
  55. retries: "{{ matrix_container_retries_count }}"
  56. delay: "{{ matrix_container_retries_delay }}"
  57. until: result is not failed
  58. - when: "matrix_synapse_container_image_customizations_enabled | bool"
  59. block:
  60. - name: Ensure customizations Dockerfile is created
  61. ansible.builtin.template:
  62. src: "{{ role_path }}/templates/synapse/customizations/Dockerfile.j2"
  63. dest: "{{ matrix_synapse_customized_docker_src_files_path }}/Dockerfile"
  64. owner: "{{ matrix_user_username }}"
  65. group: "{{ matrix_user_groupname }}"
  66. mode: 0640
  67. - name: Ensure customized Docker image for Synapse is built
  68. docker_image:
  69. name: "{{ matrix_synapse_docker_image_customized }}"
  70. source: build
  71. build:
  72. dockerfile: Dockerfile
  73. path: "{{ matrix_synapse_customized_docker_src_files_path }}"
  74. pull: true
  75. - name: Check if a Synapse signing key exists
  76. ansible.builtin.stat:
  77. path: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.key"
  78. register: matrix_synapse_signing_key_stat
  79. # We do this so that the signing key would get generated.
  80. #
  81. # This will also generate a default homeserver.yaml configuration file and a log configuration file.
  82. # We don't care about those configuration files, as we replace them with our own anyway (see below).
  83. #
  84. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  85. # a very recent docker-py version, which is not available for a lot of people yet.
  86. - name: Generate initial Synapse config and signing key
  87. ansible.builtin.command: |
  88. docker run
  89. --rm
  90. --name=matrix-config
  91. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  92. --cap-drop=ALL
  93. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
  94. -e SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
  95. -e SYNAPSE_SERVER_NAME={{ matrix_server_fqn_matrix }}
  96. -e SYNAPSE_REPORT_STATS=no
  97. {{ matrix_synapse_docker_image }}
  98. generate
  99. when: "not matrix_synapse_signing_key_stat.stat.exists"
  100. - name: Ensure Synapse homeserver config installed
  101. ansible.builtin.copy:
  102. content: "{{ matrix_synapse_configuration | to_nice_yaml(indent=2, width=999999) }}"
  103. dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  104. mode: 0644
  105. owner: "{{ matrix_user_username }}"
  106. group: "{{ matrix_user_groupname }}"
  107. - name: Ensure Synapse log config installed
  108. ansible.builtin.template:
  109. src: "{{ matrix_synapse_template_synapse_log }}"
  110. dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.log.config"
  111. mode: 0644
  112. - name: Ensure matrix-synapse.service installed
  113. ansible.builtin.template:
  114. src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse.service.j2"
  115. dest: "{{ matrix_systemd_path }}/matrix-synapse.service"
  116. mode: 0644
  117. register: matrix_synapse_systemd_service_result
  118. - name: Ensure systemd reloaded after matrix-synapse.service installation
  119. ansible.builtin.service:
  120. daemon_reload: true
  121. when: "matrix_synapse_systemd_service_result.changed"
  122. - name: Ensure matrix-synapse-register-user script created
  123. ansible.builtin.template:
  124. src: "{{ role_path }}/templates/synapse/usr-local-bin/matrix-synapse-register-user.j2"
  125. dest: "{{ matrix_local_bin_path }}/matrix-synapse-register-user"
  126. mode: 0755
  127. - name: Generate sample prometheus.yml for external scraping
  128. ansible.builtin.template:
  129. src: "{{ role_path }}/templates/synapse/prometheus/external_prometheus.yml.example.j2"
  130. dest: "{{ matrix_synapse_base_path }}/external_prometheus.yml.example"
  131. owner: "{{ matrix_user_username }}"
  132. group: "{{ matrix_user_groupname }}"
  133. mode: 0644
  134. when: matrix_synapse_metrics_proxying_enabled | bool