Matrix Docker Ansible eploy
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

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