Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

116 lines
4.7 KiB

  1. ---
  2. # This will throw a Permission Denied error if already mounted using fuse
  3. - name: Check Synapse media store path
  4. 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. 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. 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. register: matrix_synapse_git_pull_results
  26. - name: Check if Synapse Docker image exists
  27. command: "{{ matrix_host_command_docker }} images --quiet --filter 'reference={{ matrix_synapse_docker_image }}'"
  28. register: matrix_synapse_docker_image_check_result
  29. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  30. # because the latter does not support BuildKit.
  31. # See: https://github.com/ansible-collections/community.general/issues/514
  32. - name: Ensure Synapse Docker image is built
  33. shell:
  34. chdir: "{{ matrix_synapse_docker_src_files_path }}"
  35. cmd: |
  36. {{ matrix_host_command_docker }} build \
  37. -t "{{ matrix_synapse_docker_image }}" \
  38. -f docker/Dockerfile \
  39. .
  40. environment:
  41. DOCKER_BUILDKIT: 1
  42. when: "matrix_synapse_git_pull_results.changed|bool or matrix_synapse_docker_image_check_result.stdout == ''"
  43. when: "matrix_synapse_container_image_self_build|bool"
  44. - name: Ensure Synapse Docker image is pulled
  45. docker_image:
  46. name: "{{ matrix_synapse_docker_image }}"
  47. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  48. force_source: "{{ matrix_synapse_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  49. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_synapse_docker_image_force_pull }}"
  50. when: "not matrix_synapse_container_image_self_build"
  51. - name: Check if a Synapse signing key exists
  52. stat:
  53. path: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.key"
  54. register: matrix_synapse_signing_key_stat
  55. # We do this so that the signing key would get generated.
  56. #
  57. # This will also generate a default homeserver.yaml configuration file and a log configuration file.
  58. # We don't care about those configuration files, as we replace them with our own anyway (see below).
  59. #
  60. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  61. # a very recent docker-py version, which is not available for a lot of people yet.
  62. - name: Generate initial Synapse config and signing key
  63. command: |
  64. docker run
  65. --rm
  66. --name=matrix-config
  67. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  68. --cap-drop=ALL
  69. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
  70. -e SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
  71. -e SYNAPSE_SERVER_NAME={{ matrix_server_fqn_matrix }}
  72. -e SYNAPSE_REPORT_STATS=no
  73. {{ matrix_synapse_docker_image }}
  74. generate
  75. when: "not matrix_synapse_signing_key_stat.stat.exists"
  76. - name: Ensure Synapse homeserver config installed
  77. copy:
  78. content: "{{ matrix_synapse_configuration|to_nice_yaml }}"
  79. dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  80. mode: 0644
  81. owner: "{{ matrix_user_username }}"
  82. group: "{{ matrix_user_groupname }}"
  83. - name: Ensure Synapse log config installed
  84. template:
  85. src: "{{ matrix_synapse_template_synapse_log }}"
  86. dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.log.config"
  87. mode: 0644
  88. - name: Ensure matrix-synapse.service installed
  89. template:
  90. src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse.service.j2"
  91. dest: "{{ matrix_systemd_path }}/matrix-synapse.service"
  92. mode: 0644
  93. register: matrix_synapse_systemd_service_result
  94. - name: Ensure systemd reloaded after matrix-synapse.service installation
  95. service:
  96. daemon_reload: true
  97. when: "matrix_synapse_systemd_service_result.changed"
  98. - name: Ensure matrix-synapse-register-user script created
  99. template:
  100. src: "{{ role_path }}/templates/synapse/usr-local-bin/matrix-synapse-register-user.j2"
  101. dest: "{{ matrix_local_bin_path }}/matrix-synapse-register-user"
  102. mode: 0755