Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

133 строки
6.3 KiB

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