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.
 
 

110 rivejä
4.4 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: yes
  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. - name: Ensure Synapse repository is present on self-build
  19. git:
  20. repo: "{{ matrix_synapse_container_image_self_build_repo }}"
  21. dest: "{{ matrix_synapse_docker_src_files_path }}"
  22. version: "{{ matrix_synapse_docker_image.split(':')[1] }}"
  23. force: "yes"
  24. register: matrix_synapse_git_pull_results
  25. when: "matrix_synapse_container_image_self_build|bool"
  26. - name: Ensure Synapse Docker image is built
  27. docker_image:
  28. name: "{{ matrix_synapse_docker_image }}"
  29. source: build
  30. force_source: "{{ matrix_synapse_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  31. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_synapse_git_pull_results.changed }}"
  32. build:
  33. dockerfile: docker/Dockerfile
  34. path: "{{ matrix_synapse_docker_src_files_path }}"
  35. pull: yes
  36. when: "matrix_synapse_container_image_self_build|bool"
  37. - name: Ensure Synapse Docker image is pulled
  38. docker_image:
  39. name: "{{ matrix_synapse_docker_image }}"
  40. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  41. force_source: "{{ matrix_synapse_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  42. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_synapse_docker_image_force_pull }}"
  43. when: "not matrix_synapse_container_image_self_build"
  44. - name: Check if a Synapse signing key exists
  45. stat:
  46. path: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.key"
  47. register: matrix_synapse_signing_key_stat
  48. # We do this so that the signing key would get generated.
  49. #
  50. # This will also generate a default homeserver.yaml configuration file and a log configuration file.
  51. # We don't care about those configuraiton files, as we replace them with our own anyway (see below).
  52. #
  53. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  54. # a very recent version, which is not available for a lot of people yet.
  55. - name: Generate initial Synapse config and signing key
  56. command: |
  57. docker run
  58. --rm
  59. --name=matrix-config
  60. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  61. --cap-drop=ALL
  62. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
  63. -e UID={{ matrix_user_uid }}
  64. -e GID={{ matrix_user_gid }}
  65. -e SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
  66. -e SYNAPSE_SERVER_NAME={{ matrix_server_fqn_matrix }}
  67. -e SYNAPSE_REPORT_STATS=no
  68. {{ matrix_synapse_docker_image }}
  69. generate
  70. when: "not matrix_synapse_signing_key_stat.stat.exists"
  71. - name: Ensure Synapse homeserver config installed
  72. copy:
  73. content: "{{ matrix_synapse_configuration|to_nice_yaml }}"
  74. dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  75. mode: 0644
  76. owner: "{{ matrix_user_username }}"
  77. group: "{{ matrix_user_groupname }}"
  78. - name: Ensure Synapse log config installed
  79. template:
  80. src: "{{ matrix_synapse_template_synapse_log }}"
  81. dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.log.config"
  82. mode: 0644
  83. - name: Ensure matrix-synapse.service installed
  84. template:
  85. src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse.service.j2"
  86. dest: "{{ matrix_systemd_path }}/matrix-synapse.service"
  87. mode: 0644
  88. register: matrix_synapse_systemd_service_result
  89. - name: Ensure systemd reloaded after matrix-synapse.service installation
  90. service:
  91. daemon_reload: yes
  92. when: "matrix_synapse_systemd_service_result.changed"
  93. - name: Ensure matrix-synapse-register-user script created
  94. template:
  95. src: "{{ role_path }}/templates/synapse/usr-local-bin/matrix-synapse-register-user.j2"
  96. dest: "{{ matrix_local_bin_path }}/matrix-synapse-register-user"
  97. mode: 0755