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

136 строки
5.5 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-mautrix-telegram role needs to execute before the matrix-synapse role.
  8. when: "matrix_synapse_role_executed|default(False)"
  9. - name: Ensure Mautrix Telegram image is pulled
  10. docker_image:
  11. name: "{{ matrix_mautrix_telegram_docker_image }}"
  12. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  13. - name: Ensure Mautrix Telegram base directory exists
  14. file:
  15. path: "{{ matrix_mautrix_telegram_base_path }}"
  16. state: directory
  17. mode: 0750
  18. owner: "{{ matrix_user_username }}"
  19. group: "{{ matrix_user_username }}"
  20. - name: Check if a mautrix-telegram configuration file exists
  21. stat:
  22. path: "{{ matrix_mautrix_telegram_base_path }}/config.yaml"
  23. register: mautrix_telegram_config_file_stat
  24. - name: Ensure Matrix Mautrix telegram config installed
  25. template:
  26. src: "{{ role_path }}/templates/config.yaml.j2"
  27. dest: "{{ matrix_mautrix_telegram_base_path }}/config.yaml"
  28. mode: 0644
  29. owner: "{{ matrix_user_username }}"
  30. group: "{{ matrix_user_username }}"
  31. when: "not mautrix_telegram_config_file_stat.stat.exists"
  32. - name: (Migration) Fix up old configuration
  33. lineinfile:
  34. path: "{{ matrix_mautrix_telegram_base_path }}/config.yaml"
  35. regexp: "{{ item.regexp }}"
  36. line: "{{ item.line }}"
  37. backrefs: yes
  38. with_items:
  39. - {'regexp': '^(\s+)filename: \./mautrix-telegram.log', 'line': '\1filename: /data/mautrix-telegram.log'}
  40. - {'regexp': '^(\s+)database:', 'line': '\1database: sqlite:////data/mautrix-telegram.db'}
  41. when: "mautrix_telegram_config_file_stat.stat.exists"
  42. - name: Ensure matrix-mautrix-telegram.service installed
  43. template:
  44. src: "{{ role_path }}/templates/systemd/matrix-mautrix-telegram.service.j2"
  45. dest: "/etc/systemd/system/matrix-mautrix-telegram.service"
  46. mode: 0644
  47. register: matrix_mautrix_telegram_systemd_service_result
  48. - name: Ensure systemd reloaded after matrix-mautrix-telegram.service installation
  49. service:
  50. daemon_reload: yes
  51. when: "matrix_mautrix_telegram_systemd_service_result.changed"
  52. - name: Check if a mautrix-telegram registration file exists
  53. stat:
  54. path: "{{ matrix_mautrix_telegram_base_path }}/registration.yaml"
  55. register: mautrix_telegram_registration_file_stat
  56. - name: Generate matrix-mautrix-telegram registration.yaml if it doesn't exist
  57. shell:
  58. cmd: >-
  59. /usr/bin/docker run
  60. --rm
  61. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  62. --cap-drop=ALL
  63. --name matrix-mautrix-telegram-gen
  64. -v {{ matrix_mautrix_telegram_base_path }}:/data:z
  65. {{ matrix_mautrix_telegram_docker_image }}
  66. python3 -m mautrix_telegram -g -c /data/config.yaml -r /data/registration.yaml
  67. when: "not mautrix_telegram_registration_file_stat.stat.exists"
  68. # If the matrix-synapse role is not used, these variables may not exist.
  69. - set_fact:
  70. matrix_synapse_container_extra_arguments: >
  71. {{ matrix_synapse_container_extra_arguments|default([]) }}
  72. +
  73. {{ ["--mount type=bind,src={{ matrix_mautrix_telegram_base_path }}/registration.yaml,dst=/matrix-mautrix-telegram-registration.yaml,ro"] }}
  74. matrix_synapse_app_service_config_files: >
  75. {{ matrix_synapse_app_service_config_files|default([]) }}
  76. +
  77. {{ ["/matrix-mautrix-telegram-registration.yaml"] }}
  78. - block:
  79. - name: Fail if matrix-nginx-proxy role already executed
  80. fail:
  81. msg: >-
  82. Trying to append Mautrix Telegram's reverse-proxying configuration to matrix-nginx-proxy,
  83. but it's pointless since the matrix-nginx-proxy role had already executed.
  84. To fix this, please change the order of roles in your plabook,
  85. so that the matrix-nginx-proxy role would run after the matrix-bridge-mautrix-telegram role.
  86. when: matrix_nginx_proxy_role_executed|default(False)|bool
  87. - name: Generate Mautrix Telegram proxying configuration for matrix-nginx-proxy
  88. set_fact:
  89. matrix_mautrix_telegram_matrix_nginx_proxy_configuration: |
  90. location {{ matrix_mautrix_telegram_public_endpoint }} {
  91. {% if matrix_nginx_proxy_enabled|default(False) %}
  92. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  93. resolver 127.0.0.11 valid=5s;
  94. set $backend "matrix-mautrix-telegram:8080";
  95. proxy_pass http://$backend;
  96. {% else %}
  97. {# Generic configuration for use outside of our container setup #}
  98. proxy_pass http://127.0.0.1:9006;
  99. {% endif %}
  100. }
  101. - name: Register Mautrix Telegram proxying configuration with matrix-nginx-proxy
  102. set_fact:
  103. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: |
  104. {{
  105. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([])
  106. +
  107. [matrix_mautrix_telegram_matrix_nginx_proxy_configuration]
  108. }}
  109. tags:
  110. - always
  111. - name: Warn about reverse-proxying if matrix-nginx-proxy not used
  112. debug:
  113. msg: >-
  114. NOTE: You've enabled the Mautrix Telegram bridge but are not using the matrix-nginx-proxy
  115. reverse proxy.
  116. Please make sure that you're proxying the `{{ matrix_mautrix_telegram_public_endpoint }}`
  117. URL endpoint to the matrix-mautrix-telegram container.
  118. You can expose the container's port using the `matrix_mautrix_telegram_container_http_host_bind_port` variable.
  119. when: "matrix_nginx_proxy_enabled is not defined"