Matrix Docker Ansible eploy
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

132 líneas
5.6 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. - block:
  19. - name: Ensure Synapse repository is present on self-build
  20. ansible.builtin.git:
  21. repo: "{{ matrix_synapse_container_image_self_build_repo }}"
  22. dest: "{{ matrix_synapse_docker_src_files_path }}"
  23. version: "{{ matrix_synapse_docker_image.split(':')[1] }}"
  24. force: "yes"
  25. become: true
  26. become_user: "{{ matrix_user_username }}"
  27. register: matrix_synapse_git_pull_results
  28. - name: Check if Synapse Docker image exists
  29. ansible.builtin.command: "{{ matrix_host_command_docker }} images --quiet --filter 'reference={{ matrix_synapse_docker_image }}'"
  30. register: matrix_synapse_docker_image_check_result
  31. changed_when: false
  32. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  33. # because the latter does not support BuildKit.
  34. # See: https://github.com/ansible-collections/community.general/issues/514
  35. - name: Ensure Synapse Docker image is built
  36. ansible.builtin.shell:
  37. chdir: "{{ matrix_synapse_docker_src_files_path }}"
  38. cmd: |
  39. {{ matrix_host_command_docker }} build \
  40. -t "{{ matrix_synapse_docker_image }}" \
  41. -f docker/Dockerfile \
  42. .
  43. environment:
  44. DOCKER_BUILDKIT: 1
  45. when: "matrix_synapse_git_pull_results.changed | bool or matrix_synapse_docker_image_check_result.stdout == ''"
  46. when: "matrix_synapse_container_image_self_build | bool"
  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. - name: Check if a Synapse signing key exists
  59. ansible.builtin.stat:
  60. path: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.key"
  61. register: matrix_synapse_signing_key_stat
  62. # We do this so that the signing key would get generated.
  63. #
  64. # This will also generate a default homeserver.yaml configuration file and a log configuration file.
  65. # We don't care about those configuration files, as we replace them with our own anyway (see below).
  66. #
  67. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  68. # a very recent docker-py version, which is not available for a lot of people yet.
  69. - name: Generate initial Synapse config and signing key
  70. ansible.builtin.command: |
  71. docker run
  72. --rm
  73. --name=matrix-config
  74. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  75. --cap-drop=ALL
  76. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
  77. -e SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
  78. -e SYNAPSE_SERVER_NAME={{ matrix_server_fqn_matrix }}
  79. -e SYNAPSE_REPORT_STATS=no
  80. {{ matrix_synapse_docker_image }}
  81. generate
  82. when: "not matrix_synapse_signing_key_stat.stat.exists"
  83. - name: Ensure Synapse homeserver config installed
  84. ansible.builtin.copy:
  85. content: "{{ matrix_synapse_configuration | to_nice_yaml(indent=2, width=999999) }}"
  86. dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  87. mode: 0644
  88. owner: "{{ matrix_user_username }}"
  89. group: "{{ matrix_user_groupname }}"
  90. - name: Ensure Synapse log config installed
  91. ansible.builtin.template:
  92. src: "{{ matrix_synapse_template_synapse_log }}"
  93. dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.log.config"
  94. mode: 0644
  95. - name: Ensure matrix-synapse.service installed
  96. ansible.builtin.template:
  97. src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse.service.j2"
  98. dest: "{{ matrix_systemd_path }}/matrix-synapse.service"
  99. mode: 0644
  100. register: matrix_synapse_systemd_service_result
  101. - name: Ensure systemd reloaded after matrix-synapse.service installation
  102. ansible.builtin.service:
  103. daemon_reload: true
  104. when: "matrix_synapse_systemd_service_result.changed"
  105. - name: Ensure matrix-synapse-register-user script created
  106. ansible.builtin.template:
  107. src: "{{ role_path }}/templates/synapse/usr-local-bin/matrix-synapse-register-user.j2"
  108. dest: "{{ matrix_local_bin_path }}/matrix-synapse-register-user"
  109. mode: 0755
  110. - name: Generate sample prometheus.yml for external scraping
  111. ansible.builtin.template:
  112. src: "{{ role_path }}/templates/synapse/prometheus/external_prometheus.yml.example.j2"
  113. dest: "{{ matrix_synapse_base_path }}/external_prometheus.yml.example"
  114. owner: "{{ matrix_user_username }}"
  115. group: "{{ matrix_user_groupname }}"
  116. mode: 0644
  117. when: matrix_synapse_metrics_proxying_enabled | bool