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

139 строки
5.7 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. - set_fact:
  69. matrix_synapse_app_service_config_file_mautrix_telegram: '/app-registration/mautrix-telegram.yml'
  70. # If the matrix-synapse role is not used, these variables may not exist.
  71. - set_fact:
  72. matrix_synapse_container_additional_volumes: >
  73. {{ matrix_synapse_container_additional_volumes|default([]) }}
  74. +
  75. {{ [{'src': '{{ matrix_mautrix_telegram_base_path }}/registration.yaml', 'dst': '{{ matrix_synapse_app_service_config_file_mautrix_telegram }}', 'options': 'ro'}] }}
  76. matrix_synapse_app_service_config_files: >
  77. {{ matrix_synapse_app_service_config_files|default([]) }}
  78. +
  79. {{ ["{{ matrix_synapse_app_service_config_file_mautrix_telegram }}"] | to_nice_json }}
  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"