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.
 
 

146 regels
5.8 KiB

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