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.
 
 

149 lines
7.2 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. 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. - 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. - set_fact:
  14. matrix_synapse_container_extra_arguments: >
  15. {{
  16. matrix_synapse_container_extra_arguments|default([])
  17. +
  18. ["--mount type=bind,src={{ matrix_hookshot_base_path }}/registration.yml,dst=/hookshot-registration.yml,ro"]
  19. }}
  20. matrix_synapse_app_service_config_files: >
  21. {{
  22. matrix_synapse_app_service_config_files|default([])
  23. +
  24. ["/hookshot-registration.yml"]
  25. }}
  26. when: matrix_hookshot_enabled|bool
  27. - block:
  28. - name: Fail if matrix-nginx-proxy role already executed
  29. fail:
  30. msg: >-
  31. Trying to append hookshot's reverse-proxying configuration to matrix-nginx-proxy,
  32. but it's pointless since the matrix-nginx-proxy role had already executed.
  33. To fix this, please change the order of roles in your playbook,
  34. so that the matrix-nginx-proxy role would run after the matrix-bridge-hookshot role.
  35. when: matrix_nginx_proxy_role_executed|default(False)|bool
  36. - name: Generate Matrix hookshot proxying configuration for matrix-nginx-proxy
  37. set_fact:
  38. matrix_hookshot_matrix_nginx_proxy_configuration: |
  39. location ~ ^{{ matrix_hookshot_appservice_endpoint }}/(.*)$ {
  40. {% if matrix_nginx_proxy_enabled|default(False) %}
  41. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  42. resolver 127.0.0.11 valid=5s;
  43. set $backend "{{ matrix_hookshot_container_url }}:{{ matrix_hookshot_appservice_port }}";
  44. proxy_pass http://$backend/$1;
  45. {% else %}
  46. {# Generic configuration for use outside of our container setup #}
  47. proxy_pass http://127.0.0.1:{{ matrix_hookshot_appservice_port }}/$1;
  48. {% endif %}
  49. proxy_set_header Host $host;
  50. }
  51. {% if matrix_hookshot_provisioning_enabled %}
  52. location ~ ^{{ matrix_hookshot_provisioning_endpoint }}/(.*)$ {
  53. {% if matrix_nginx_proxy_enabled|default(False) %}
  54. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  55. resolver 127.0.0.11 valid=5s;
  56. set $backend "{{ matrix_hookshot_container_url }}:{{ matrix_hookshot_provisioning_port }}";
  57. proxy_pass http://$backend{{ matrix_hookshot_provisioning_internal }}/$1$is_args$args;
  58. {% else %}
  59. {# Generic configuration for use outside of our container setup #}
  60. proxy_pass http://127.0.0.1:{{ matrix_hookshot_provisioning_port }}{{ matrix_hookshot_provisioning_internal }}/$1$is_args$args;
  61. {% endif %}
  62. proxy_set_header Host $host;
  63. }
  64. {% endif %}
  65. {% if matrix_hookshot_widgets_enabled %}
  66. location ~ ^{{ matrix_hookshot_widgets_endpoint }}/(.*)$ {
  67. {% if matrix_nginx_proxy_enabled|default(False) %}
  68. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  69. resolver 127.0.0.11 valid=5s;
  70. set $backend "{{ matrix_hookshot_container_url }}:{{ matrix_hookshot_widgets_port }}";
  71. proxy_pass http://$backend{{ matrix_hookshot_widgets_internal }}/$1$is_args$args;
  72. {% else %}
  73. {# Generic configuration for use outside of our container setup #}
  74. proxy_pass http://127.0.0.1:{{ matrix_hookshot_widgets_port }}{{ matrix_hookshot_widgets_internal }}/$1$is_args$args;
  75. {% endif %}
  76. proxy_set_header Host $host;
  77. }
  78. {% endif %}
  79. location ~ ^{{ matrix_hookshot_webhook_endpoint }}/(.*)$ {
  80. {% if matrix_nginx_proxy_enabled|default(False) %}
  81. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  82. resolver 127.0.0.11 valid=5s;
  83. set $backend "{{ matrix_hookshot_container_url }}:{{ matrix_hookshot_webhook_port }}";
  84. proxy_pass http://$backend/$1$is_args$args;
  85. {% else %}
  86. {# Generic configuration for use outside of our container setup #}
  87. proxy_pass http://127.0.0.1:{{ matrix_hookshot_webhook_port }}/$1$is_args$args;
  88. {% endif %}
  89. proxy_set_header Host $host;
  90. }
  91. - name: Register hookshot proxying configuration with matrix-nginx-proxy
  92. set_fact:
  93. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: |
  94. {{
  95. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([])
  96. +
  97. [matrix_hookshot_matrix_nginx_proxy_configuration]
  98. }}
  99. - name: Generate Matrix hookshot proxying configuration for matrix-nginx-proxy
  100. set_fact:
  101. matrix_hookshot_matrix_nginx_proxy_metrics_configuration: |
  102. {% if matrix_hookshot_metrics_enabled and matrix_hookshot_proxy_metrics %}
  103. location {{ matrix_hookshot_metrics_endpoint }} {
  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. proxy_set_header Host $host;
  114. {% if matrix_hookshot_proxy_metrics_basic_auth_enabled %}
  115. auth_basic "protected";
  116. auth_basic_user_file /nginx-data/matrix-synapse-metrics-htpasswd;
  117. {% endif %}
  118. }
  119. {% endif %}
  120. - name: Register hookshot metrics proxying configuration with matrix-nginx-proxy
  121. set_fact:
  122. matrix_nginx_proxy_proxy_grafana_additional_server_configuration_blocks: |
  123. {{
  124. matrix_nginx_proxy_proxy_grafana_additional_server_configuration_blocks|default([])
  125. +
  126. [matrix_hookshot_matrix_nginx_proxy_metrics_configuration]
  127. }}
  128. tags:
  129. - always
  130. when: matrix_hookshot_enabled|bool
  131. - name: Warn about reverse-proxying if matrix-nginx-proxy not used
  132. debug:
  133. msg: >-
  134. NOTE: You've enabled the hookshot bridge but are not using the matrix-nginx-proxy
  135. reverse proxy.
  136. Please make sure that you're proxying the `{{ matrix_hookshot_public_endpoint }}`
  137. URL endpoint to the matrix-hookshot container.
  138. You can expose the container's ports using the `matrix_hookshot_container_http_host_bind_ports` variable.
  139. when: "matrix_hookshot_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool"