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.
 
 

117 lines
4.7 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. - stat: "path={{ matrix_mautrix_telegram_base_path }}/config.yaml"
  15. register: mautrix_config_file
  16. - name: Ensure Matrix Mautrix telegram config installed
  17. template:
  18. src: "{{ role_path }}/templates/ext/mautrix-telegram/config.yaml.j2"
  19. dest: "{{ matrix_mautrix_telegram_base_path }}/config.yaml"
  20. mode: 0644
  21. owner: "{{ matrix_user_username }}"
  22. group: "{{ matrix_user_username }}"
  23. when: "matrix_mautrix_telegram_enabled and mautrix_config_file.stat.exists == False"
  24. - name: Ensure matrix-mautrix-telegram.service installed
  25. template:
  26. src: "{{ role_path }}/templates/ext/mautrix-telegram/systemd/matrix-mautrix-telegram.service.j2"
  27. dest: "/etc/systemd/system/matrix-mautrix-telegram.service"
  28. mode: 0644
  29. when: "matrix_mautrix_telegram_enabled"
  30. - stat:
  31. path: "{{ matrix_mautrix_telegram_base_path }}/registration.yaml"
  32. register: mautrix_telegram_registration_file
  33. - name: Generate matrix-mautrix-telegram registration.yaml if it doesn't exist
  34. shell: /usr/bin/docker run --rm --name matrix-mautrix-telegram-gen -v {{ matrix_mautrix_telegram_base_path }}:/data:z {{ matrix_mautrix_telegram_docker_image }} python3 -m mautrix_telegram -g -c /data/config.yaml -r /data/registration.yaml
  35. when: "matrix_mautrix_telegram_enabled and mautrix_telegram_registration_file.stat.exists == False"
  36. - set_fact:
  37. matrix_synapse_app_service_config_file_mautrix_telegram: '/app-registration/mautrix-telegram.yml'
  38. - set_fact:
  39. matrix_synapse_container_additional_volumes: >
  40. {{ matrix_synapse_container_additional_volumes }}
  41. +
  42. {{ [{'src': '{{ matrix_mautrix_telegram_base_path }}/registration.yaml', 'dst': '{{ matrix_synapse_app_service_config_file_mautrix_telegram }}', 'options': 'ro'}] }}
  43. when: "matrix_mautrix_telegram_enabled"
  44. - set_fact:
  45. matrix_synapse_app_service_config_files: >
  46. {{ matrix_synapse_app_service_config_files }}
  47. +
  48. {{ ["{{ matrix_synapse_app_service_config_file_mautrix_telegram }}"] | to_nice_json }}
  49. when: "matrix_mautrix_telegram_enabled"
  50. - block:
  51. - name: Fail if matrix-nginx-proxy role already executed
  52. fail:
  53. msg: >
  54. Trying to append Mautrix Telegram's reverse-proxying configuration to matrix-nginx-proxy,
  55. but it's pointless since the matrix-nginx-proxy role had already executed.
  56. To fix this, please change the order of roles in your plabook,
  57. so that the matrix-nginx-proxy role would run after the matrix-synapse role.
  58. when: "matrix_nginx_proxy_role_executed"
  59. - name: Generate Mautrix Telegram proxying configuration for matrix-nginx-proxy
  60. set_fact:
  61. matrix_mautrix_telegram_matrix_nginx_proxy_configuration: |
  62. location {{ matrix_mautrix_telegram_public_endpoint }} {
  63. {% if matrix_nginx_proxy_enabled %}
  64. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  65. resolver 127.0.0.11 valid=5s;
  66. set $backend "matrix-mautrix-telegram:8080";
  67. proxy_pass http://$backend;
  68. {% else %}
  69. {# Generic configuration for use outside of our container setup #}
  70. proxy_pass http://localhost:8080;
  71. {% endif %}
  72. }
  73. - name: Register Mautrix Telegram proxying configuration with matrix-nginx-proxy
  74. set_fact:
  75. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: |
  76. {{
  77. matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks
  78. +
  79. [matrix_mautrix_telegram_matrix_nginx_proxy_configuration]
  80. }}
  81. when: "matrix_mautrix_telegram_enabled and matrix_nginx_proxy_enabled|default(False)"
  82. tags:
  83. - always
  84. - name: Warn about reverse-proxying if matrix-nginx-proxy not used
  85. debug:
  86. msg: >
  87. NOTE: You've enabled the Mautrix Telegram bridge but are not using the matrix-nginx-proxy
  88. reverse proxy.
  89. Please make sure that you're proxying the `{{ matrix_mautrix_telegram_public_endpoint }}`
  90. URL endpoint to the matrix-mautrix-telegram container.
  91. when: "matrix_mautrix_telegram_enabled and matrix_nginx_proxy_enabled is not defined"
  92. #
  93. # Tasks related to getting rid of matrix-mautrix-telegram (if it was previously enabled)
  94. #
  95. - name: Ensure matrix-mautrix-telegram.service doesn't exist
  96. file:
  97. path: "/etc/systemd/system/matrix-mautrix-telegram.service"
  98. state: absent
  99. when: "not matrix_mautrix_telegram_enabled"