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

142 строки
7.4 KiB

  1. ---
  2. # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist.
  3. # We don't want to fail in such cases.
  4. - name: Fail if matrix-synapse role already executed
  5. ansible.builtin.fail:
  6. msg: >-
  7. The matrix-bridge-hookshot role needs to execute before the matrix-synapse role.
  8. when: "matrix_hookshot_enabled and matrix_synapse_role_executed | default(False)"
  9. - ansible.builtin.set_fact:
  10. matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-hookshot.service'] }}"
  11. when: matrix_hookshot_enabled | bool
  12. # If the matrix-synapse role is not used, these variables may not exist.
  13. - ansible.builtin.set_fact:
  14. matrix_homeserver_container_runtime_injected_arguments: >
  15. {{
  16. matrix_homeserver_container_runtime_injected_arguments | default([])
  17. +
  18. ["--mount type=bind,src={{ matrix_hookshot_base_path }}/registration.yml,dst=/hookshot-registration.yml,ro"]
  19. }}
  20. matrix_homeserver_app_service_runtime_injected_config_files: >
  21. {{
  22. matrix_homeserver_app_service_runtime_injected_config_files | default([])
  23. +
  24. ["/hookshot-registration.yml"]
  25. }}
  26. when: matrix_hookshot_enabled | bool
  27. - when: matrix_hookshot_enabled | bool
  28. block:
  29. - name: Fail if matrix-nginx-proxy role already executed
  30. ansible.builtin.fail:
  31. msg: >-
  32. Trying to append hookshot's reverse-proxying configuration to matrix-nginx-proxy,
  33. but it's pointless since the matrix-nginx-proxy role had already executed.
  34. To fix this, please change the order of roles in your playbook,
  35. so that the matrix-nginx-proxy role would run after the matrix-bridge-hookshot role.
  36. when: matrix_nginx_proxy_role_executed | default(False) | bool
  37. - name: Generate Matrix hookshot proxying configuration for matrix-nginx-proxy
  38. ansible.builtin.set_fact:
  39. matrix_hookshot_matrix_nginx_proxy_configuration: |
  40. location ~ ^{{ matrix_hookshot_appservice_endpoint }}/(.*)$ {
  41. {% if matrix_nginx_proxy_enabled | default(False) %}
  42. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  43. resolver 127.0.0.11 valid=5s;
  44. set $backend "{{ matrix_hookshot_container_url }}:{{ matrix_hookshot_appservice_port }}";
  45. proxy_pass http://$backend/$1;
  46. {% else %}
  47. {# Generic configuration for use outside of our container setup #}
  48. proxy_pass http://127.0.0.1:{{ matrix_hookshot_appservice_port }}/$1;
  49. {% endif %}
  50. proxy_set_header Host $host;
  51. }
  52. {% if matrix_hookshot_provisioning_enabled %}
  53. location ~ ^{{ matrix_hookshot_provisioning_endpoint }}/(.*)$ {
  54. {% if matrix_nginx_proxy_enabled | default(False) %}
  55. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  56. resolver 127.0.0.11 valid=5s;
  57. set $backend "{{ matrix_hookshot_container_url }}:{{ matrix_hookshot_provisioning_port }}";
  58. proxy_pass http://$backend{{ matrix_hookshot_provisioning_internal }}/$1$is_args$args;
  59. {% else %}
  60. {# Generic configuration for use outside of our container setup #}
  61. proxy_pass http://127.0.0.1:{{ matrix_hookshot_provisioning_port }}{{ matrix_hookshot_provisioning_internal }}/$1$is_args$args;
  62. {% endif %}
  63. proxy_set_header Host $host;
  64. }
  65. {% endif %}
  66. {% if matrix_hookshot_widgets_enabled %}
  67. location ~ ^{{ matrix_hookshot_widgets_endpoint }}/(.*)$ {
  68. {% if matrix_nginx_proxy_enabled | default(False) %}
  69. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  70. resolver 127.0.0.11 valid=5s;
  71. set $backend "{{ matrix_hookshot_container_url }}:{{ matrix_hookshot_widgets_port }}";
  72. proxy_pass http://$backend{{ matrix_hookshot_widgets_internal }}/$1$is_args$args;
  73. {% else %}
  74. {# Generic configuration for use outside of our container setup #}
  75. proxy_pass http://127.0.0.1:{{ matrix_hookshot_widgets_port }}{{ matrix_hookshot_widgets_internal }}/$1$is_args$args;
  76. {% endif %}
  77. proxy_set_header Host $host;
  78. }
  79. {% endif %}
  80. location ~ ^{{ matrix_hookshot_webhook_endpoint }}/(.*)$ {
  81. {% if matrix_nginx_proxy_enabled | default(False) %}
  82. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  83. resolver 127.0.0.11 valid=5s;
  84. set $backend "{{ matrix_hookshot_container_url }}:{{ matrix_hookshot_webhook_port }}";
  85. proxy_pass http://$backend/$1$is_args$args;
  86. {% else %}
  87. {# Generic configuration for use outside of our container setup #}
  88. proxy_pass http://127.0.0.1:{{ matrix_hookshot_webhook_port }}/$1$is_args$args;
  89. {% endif %}
  90. proxy_set_header Host $host;
  91. }
  92. - name: Register hookshot proxying configuration with matrix-nginx-proxy
  93. ansible.builtin.set_fact:
  94. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: |
  95. {{
  96. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([])
  97. +
  98. [matrix_hookshot_matrix_nginx_proxy_configuration]
  99. }}
  100. - name: Generate hookshot metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/hookshot)
  101. ansible.builtin.set_fact:
  102. matrix_hookshot_matrix_nginx_proxy_metrics_configuration_matrix_domain: |
  103. location /metrics/hookshot {
  104. {% if matrix_nginx_proxy_enabled | default(False) %}
  105. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  106. resolver 127.0.0.11 valid=5s;
  107. set $backend "{{ matrix_hookshot_container_url }}:{{ matrix_hookshot_metrics_port }}";
  108. proxy_pass http://$backend/metrics;
  109. {% else %}
  110. {# Generic configuration for use outside of our container setup #}
  111. proxy_pass http://127.0.0.1:{{ matrix_hookshot_metrics_port }}/metrics;
  112. {% endif %}
  113. }
  114. when: matrix_hookshot_metrics_enabled | bool and matrix_hookshot_metrics_proxying_enabled | bool
  115. - name: Register hookshot metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/hookshot)
  116. ansible.builtin.set_fact:
  117. matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: |
  118. {{
  119. matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([])
  120. +
  121. [matrix_hookshot_matrix_nginx_proxy_metrics_configuration_matrix_domain]
  122. }}
  123. when: matrix_hookshot_metrics_enabled | bool and matrix_hookshot_metrics_proxying_enabled | bool
  124. - name: Warn about reverse-proxying if matrix-nginx-proxy not used
  125. ansible.builtin.debug:
  126. msg: >-
  127. NOTE: You've enabled the hookshot bridge but are not using the matrix-nginx-proxy
  128. reverse proxy.
  129. Please make sure that you're proxying the `{{ matrix_hookshot_public_endpoint }}`
  130. URL endpoint to the matrix-hookshot container.
  131. You can expose the container's ports using the `matrix_hookshot_container_http_host_bind_ports` variable.
  132. when: "matrix_hookshot_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool"