Matrix Docker Ansible eploy
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

136 wiersze
6.3 KiB

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