Matrix Docker Ansible eploy
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 

140 行
5.5 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. when: "matrix_mautrix_telegram_enabled"
  42. - name: Check if a mautrix-telegram registration file exists
  43. stat:
  44. path: "{{ matrix_mautrix_telegram_base_path }}/registration.yaml"
  45. register: mautrix_telegram_registration_file_stat
  46. - name: Generate matrix-mautrix-telegram registration.yaml if it doesn't exist
  47. shell:
  48. cmd: >-
  49. /usr/bin/docker run
  50. --rm
  51. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  52. --cap-drop=ALL
  53. --name matrix-mautrix-telegram-gen
  54. -v {{ matrix_mautrix_telegram_base_path }}:/data:z
  55. {{ matrix_mautrix_telegram_docker_image }}
  56. python3 -m mautrix_telegram -g -c /data/config.yaml -r /data/registration.yaml
  57. when: "matrix_mautrix_telegram_enabled and not mautrix_telegram_registration_file_stat.stat.exists"
  58. - set_fact:
  59. matrix_synapse_app_service_config_file_mautrix_telegram: '/app-registration/mautrix-telegram.yml'
  60. - set_fact:
  61. matrix_synapse_container_additional_volumes: >
  62. {{ matrix_synapse_container_additional_volumes }}
  63. +
  64. {{ [{'src': '{{ matrix_mautrix_telegram_base_path }}/registration.yaml', 'dst': '{{ matrix_synapse_app_service_config_file_mautrix_telegram }}', 'options': 'ro'}] }}
  65. when: "matrix_mautrix_telegram_enabled"
  66. - set_fact:
  67. matrix_synapse_app_service_config_files: >
  68. {{ matrix_synapse_app_service_config_files }}
  69. +
  70. {{ ["{{ matrix_synapse_app_service_config_file_mautrix_telegram }}"] | to_nice_json }}
  71. when: "matrix_mautrix_telegram_enabled"
  72. - block:
  73. - name: Fail if matrix-nginx-proxy role already executed
  74. fail:
  75. msg: >
  76. Trying to append Mautrix Telegram's reverse-proxying configuration to matrix-nginx-proxy,
  77. but it's pointless since the matrix-nginx-proxy role had already executed.
  78. To fix this, please change the order of roles in your plabook,
  79. so that the matrix-nginx-proxy role would run after the matrix-synapse role.
  80. when: "matrix_nginx_proxy_role_executed"
  81. - name: Generate Mautrix Telegram proxying configuration for matrix-nginx-proxy
  82. set_fact:
  83. matrix_mautrix_telegram_matrix_nginx_proxy_configuration: |
  84. location {{ matrix_mautrix_telegram_public_endpoint }} {
  85. {% if matrix_nginx_proxy_enabled %}
  86. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  87. resolver 127.0.0.11 valid=5s;
  88. set $backend "matrix-mautrix-telegram:8080";
  89. proxy_pass http://$backend;
  90. {% else %}
  91. {# Generic configuration for use outside of our container setup #}
  92. proxy_pass http://localhost:8080;
  93. {% endif %}
  94. }
  95. - name: Register Mautrix Telegram proxying configuration with matrix-nginx-proxy
  96. set_fact:
  97. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: |
  98. {{
  99. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks
  100. +
  101. [matrix_mautrix_telegram_matrix_nginx_proxy_configuration]
  102. }}
  103. when: "matrix_mautrix_telegram_enabled and matrix_nginx_proxy_enabled|default(False)"
  104. tags:
  105. - always
  106. - name: Warn about reverse-proxying if matrix-nginx-proxy not used
  107. debug:
  108. msg: >
  109. NOTE: You've enabled the Mautrix Telegram bridge but are not using the matrix-nginx-proxy
  110. reverse proxy.
  111. Please make sure that you're proxying the `{{ matrix_mautrix_telegram_public_endpoint }}`
  112. URL endpoint to the matrix-mautrix-telegram container.
  113. when: "matrix_mautrix_telegram_enabled and matrix_nginx_proxy_enabled is not defined"
  114. #
  115. # Tasks related to getting rid of matrix-mautrix-telegram (if it was previously enabled)
  116. #
  117. - name: Ensure matrix-mautrix-telegram.service doesn't exist
  118. file:
  119. path: "/etc/systemd/system/matrix-mautrix-telegram.service"
  120. state: absent
  121. when: "not matrix_mautrix_telegram_enabled"