Matrix Docker Ansible eploy
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

147 rindas
6.8 KiB

  1. # SPDX-FileCopyrightText: 2018 - 2025 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2019 - 2020 MDAD project contributors
  3. # SPDX-FileCopyrightText: 2019 Dan Arnfield
  4. # SPDX-FileCopyrightText: 2020 Béla Becker
  5. # SPDX-FileCopyrightText: 2020 Chris van Dijk
  6. # SPDX-FileCopyrightText: 2020 Horvath Gergely
  7. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  8. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  9. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  10. # SPDX-FileCopyrightText: 2024 - 2025 Suguru Hirahara
  11. # SPDX-FileCopyrightText: 2024 David Mehren
  12. #
  13. # SPDX-License-Identifier: AGPL-3.0-or-later
  14. ---
  15. - when: matrix_coturn_turn_external_ip_address_auto_detection_enabled | bool
  16. block:
  17. - name: Fail if enabled, but EchoIP service URL unset
  18. when: matrix_coturn_turn_external_ip_address_auto_detection_echoip_service_url == ''
  19. ansible.builtin.fail:
  20. msg: "To use the external IP address auto-detection feature, you need to set matrix_coturn_turn_external_ip_address_auto_detection_echoip_service_url"
  21. # Note:
  22. # `ansible.builtin.uri` does not provide a way to configure whether IPv4 or IPv6 is used.
  23. # Luckily, the default instance we use does not define AAAA records for now, so it's always IPv4.
  24. - name: Fetch IP address information from EchoIP service
  25. ansible.builtin.uri:
  26. url: "{{ matrix_coturn_turn_external_ip_address_auto_detection_echoip_service_url }}"
  27. headers:
  28. Content-Type: application/json
  29. follow_redirects: none
  30. validate_certs: "{{ matrix_coturn_turn_external_ip_address_auto_detection_echoip_validate_certs }}"
  31. register: result_matrix_coturn_turn_external_ip_address_auto_detection_echoip_response
  32. ignore_errors: true
  33. check_mode: false
  34. retries: "{{ matrix_coturn_turn_external_ip_address_auto_detection_echoip_service_retries_count }}"
  35. delay: "{{ matrix_coturn_turn_external_ip_address_auto_detection_echoip_service_retries_delay }}"
  36. until: not result_matrix_coturn_turn_external_ip_address_auto_detection_echoip_response.failed
  37. - name: Fail if EchoIP service failed
  38. when: "(result_matrix_coturn_turn_external_ip_address_auto_detection_echoip_response.failed or 'json' not in result_matrix_coturn_turn_external_ip_address_auto_detection_echoip_response)"
  39. ansible.builtin.fail:
  40. msg: "Failed contacting EchoIP service API at `{{ matrix_coturn_turn_external_ip_address_auto_detection_echoip_service_url }}` (controlled by `matrix_coturn_turn_external_ip_address_auto_detection_echoip_service_url`). Full error: {{ result_matrix_coturn_turn_external_ip_address_auto_detection_echoip_response }}"
  41. - ansible.builtin.set_fact:
  42. matrix_coturn_turn_external_ip_address: "{{ result_matrix_coturn_turn_external_ip_address_auto_detection_echoip_response.json.ip }}"
  43. - name: Ensure Matrix coturn path exists
  44. ansible.builtin.file:
  45. path: "{{ item.path }}"
  46. state: directory
  47. mode: 0750
  48. owner: "{{ matrix_user_name }}"
  49. group: "{{ matrix_group_name }}"
  50. with_items:
  51. - {path: "{{ matrix_coturn_docker_src_files_path }}", when: "{{ matrix_coturn_container_image_self_build }}"}
  52. when: "item.when | bool"
  53. - name: Ensure coturn image is pulled
  54. community.docker.docker_image:
  55. name: "{{ matrix_coturn_docker_image }}"
  56. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  57. force_source: "{{ matrix_coturn_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  58. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_coturn_docker_image_force_pull }}"
  59. when: "not matrix_coturn_container_image_self_build | bool"
  60. register: result
  61. retries: "{{ devture_playbook_help_container_retries_count }}"
  62. delay: "{{ devture_playbook_help_container_retries_delay }}"
  63. until: result is not failed
  64. - when: "matrix_coturn_container_image_self_build | bool"
  65. block:
  66. - name: Ensure coturn repository is present on self-build
  67. ansible.builtin.git:
  68. repo: "{{ matrix_coturn_container_image_self_build_repo }}"
  69. dest: "{{ matrix_coturn_docker_src_files_path }}"
  70. version: "{{ matrix_coturn_container_image_self_build_repo_version }}"
  71. force: "yes"
  72. become: true
  73. become_user: "{{ matrix_user_name }}"
  74. register: matrix_coturn_git_pull_results
  75. - name: Ensure coturn Docker image is built
  76. community.docker.docker_image:
  77. name: "{{ matrix_coturn_docker_image }}"
  78. source: build
  79. force_source: "{{ matrix_coturn_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  80. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_coturn_git_pull_results.changed }}"
  81. build:
  82. dockerfile: "{{ matrix_coturn_container_image_self_build_repo_dockerfile_path }}"
  83. path: "{{ matrix_coturn_docker_src_files_path }}"
  84. pull: true
  85. - name: Ensure coturn configuration path exists
  86. ansible.builtin.file:
  87. path: "{{ matrix_coturn_base_path }}"
  88. state: directory
  89. mode: 0750
  90. owner: "{{ matrix_user_name }}"
  91. group: "{{ matrix_group_name }}"
  92. - name: Ensure turnserver.conf installed
  93. ansible.builtin.template:
  94. src: "{{ role_path }}/templates/turnserver.conf.j2"
  95. dest: "{{ matrix_coturn_config_path }}"
  96. mode: 0644
  97. owner: "{{ matrix_user_name }}"
  98. group: "{{ matrix_group_name }}"
  99. - name: Ensure coturn network is created in Docker
  100. when: matrix_coturn_container_network not in ['', 'host']
  101. community.docker.docker_network:
  102. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  103. name: "{{ matrix_coturn_container_network }}"
  104. driver: bridge
  105. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  106. - name: Ensure matrix-coturn.service installed
  107. ansible.builtin.template:
  108. src: "{{ role_path }}/templates/systemd/matrix-coturn.service.j2"
  109. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-coturn.service"
  110. mode: 0644
  111. # This may be unnecessary when more long-lived certificates are used.
  112. # We optimize for the common use-case though (short-lived Let's Encrypt certificates).
  113. # Reloading doesn't hurt anyway, so there's no need to make this more flexible.
  114. - name: Ensure reloading systemd units installed, if necessary
  115. ansible.builtin.template:
  116. src: "{{ role_path }}/templates/systemd/{{ item }}.j2"
  117. dest: "{{ devture_systemd_docker_base_systemd_path }}/{{ item }}"
  118. mode: 0644
  119. when: "matrix_coturn_tls_enabled | bool"
  120. with_items:
  121. - matrix-coturn-reload.service
  122. - matrix-coturn-reload.timer
  123. # A similar task exists in `setup_uninstall.yml`
  124. - name: Ensure reloading systemd units uninstalled, if unnecessary
  125. ansible.builtin.file:
  126. path: "{{ item }}"
  127. state: absent
  128. when: "not matrix_coturn_tls_enabled | bool"
  129. with_items:
  130. - matrix-coturn-reload.service
  131. - matrix-coturn-reload.timer