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

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