Matrix Docker Ansible eploy
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

149 líneas
5.3 KiB

  1. ---
  2. #
  3. # Tasks related to setting up Coturn
  4. #
  5. - name: Ensure Matrix Coturn path exists
  6. file:
  7. path: "{{ item.path }}"
  8. state: directory
  9. mode: 0750
  10. owner: "{{ matrix_user_username }}"
  11. group: "{{ matrix_user_groupname }}"
  12. with_items:
  13. - { path: "{{ matrix_coturn_docker_src_files_path }}", when: "{{ matrix_coturn_container_image_self_build }}"}
  14. when: matrix_coturn_enabled|bool and item.when
  15. - name: Ensure Coturn image is pulled
  16. docker_image:
  17. name: "{{ matrix_coturn_docker_image }}"
  18. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  19. force_source: "{{ matrix_coturn_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  20. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_coturn_docker_image_force_pull }}"
  21. when: matrix_coturn_enabled|bool and not matrix_coturn_container_image_self_build
  22. - name: Ensure Coturn repository is present on self-build
  23. git:
  24. repo: "{{ matrix_coturn_container_image_self_build_repo }}"
  25. dest: "{{ matrix_coturn_docker_src_files_path }}"
  26. version: "{{ matrix_coturn_docker_image.split(':')[1] }}"
  27. force: "yes"
  28. register: matrix_coturn_git_pull_results
  29. when: "matrix_coturn_enabled|bool and matrix_coturn_container_image_self_build"
  30. - name: Ensure Coturn Docker image is built
  31. docker_image:
  32. name: "{{ matrix_coturn_docker_image }}"
  33. source: build
  34. force_source: "{{ matrix_coturn_git_pull_results.changed }}"
  35. build:
  36. dockerfile: Dockerfile
  37. path: "{{ matrix_coturn_docker_src_files_path }}"
  38. pull: yes
  39. when: "matrix_coturn_enabled|bool and matrix_coturn_container_image_self_build|bool"
  40. - name: Ensure Coturn configuration path exists
  41. file:
  42. path: "{{ matrix_coturn_base_path }}"
  43. state: directory
  44. mode: 0750
  45. owner: "{{ matrix_user_username }}"
  46. group: "{{ matrix_user_groupname }}"
  47. when: matrix_coturn_enabled|bool
  48. - name: Ensure turnserver.conf installed
  49. template:
  50. src: "{{ role_path }}/templates/turnserver.conf.j2"
  51. dest: "{{ matrix_coturn_config_path }}"
  52. mode: 0644
  53. when: matrix_coturn_enabled|bool
  54. # `docker_network` doesn't work as expected when the given network
  55. # is a substring of a network that already exists.
  56. #
  57. # See our other comments in `roles/matrix-base/tasks/setup_matrix_base.yml`
  58. - name: Check existence of Coturn network in Docker
  59. shell:
  60. cmd: "docker network ls -q --filter='name=^{{ matrix_coturn_docker_network }}$'"
  61. register: matrix_coturn_result_docker_network
  62. changed_when: false
  63. when: matrix_coturn_enabled|bool
  64. check_mode: no
  65. - name: Create Coturn network in Docker
  66. shell:
  67. cmd: "docker network create --driver=bridge {{ matrix_coturn_docker_network }}"
  68. when: "matrix_coturn_enabled|bool and matrix_coturn_result_docker_network.stdout == '' and not ansible_check_mode"
  69. - name: Ensure matrix-coturn.service installed
  70. template:
  71. src: "{{ role_path }}/templates/systemd/matrix-coturn.service.j2"
  72. dest: "{{ matrix_systemd_path }}/matrix-coturn.service"
  73. mode: 0644
  74. register: matrix_coturn_systemd_service_result
  75. when: matrix_coturn_enabled|bool
  76. - name: Ensure systemd reloaded after matrix-coturn.service installation
  77. service:
  78. daemon_reload: yes
  79. when: "matrix_coturn_enabled|bool and matrix_coturn_systemd_service_result.changed"
  80. # This may be unnecessary when more long-lived certificates are used.
  81. # We optimize for the common use-case though (short-lived Let's Encrypt certificates).
  82. # Reloading doesn't hurt anyway, so there's no need to make this more flexible.
  83. - name: Ensure periodic reloading of matrix-coturn is configured for SSL renewal (matrix-coturn-reload)
  84. template:
  85. src: "{{ role_path }}/templates/cron.d/matrix-coturn-ssl-reload.j2"
  86. dest: /etc/cron.d/matrix-coturn-ssl-reload
  87. mode: 0644
  88. when: "matrix_coturn_enabled|bool and matrix_coturn_tls_enabled|bool"
  89. #
  90. # Tasks related to getting rid of Coturn (if it was previously enabled)
  91. #
  92. - name: Ensure matrix-coturn-ssl-reload cronjob removed
  93. file:
  94. path: /etc/cron.d/matrix-coturn-ssl-reload
  95. state: absent
  96. when: "not matrix_coturn_enabled|bool or not matrix_coturn_tls_enabled|bool"
  97. - name: Check existence of matrix-coturn service
  98. stat:
  99. path: "{{ matrix_systemd_path }}/matrix-coturn.service"
  100. register: matrix_coturn_service_stat
  101. when: "not matrix_coturn_enabled|bool"
  102. - name: Ensure matrix-coturn is stopped
  103. service:
  104. name: matrix-coturn
  105. state: stopped
  106. daemon_reload: yes
  107. register: stopping_result
  108. when: "not matrix_coturn_enabled|bool and matrix_coturn_service_stat.stat.exists"
  109. - name: Ensure matrix-coturn.service doesn't exist
  110. file:
  111. path: "{{ matrix_systemd_path }}/matrix-coturn.service"
  112. state: absent
  113. when: "not matrix_coturn_enabled|bool and matrix_coturn_service_stat.stat.exists"
  114. - name: Ensure systemd reloaded after matrix-coturn.service removal
  115. service:
  116. daemon_reload: yes
  117. when: "not matrix_coturn_enabled|bool and matrix_coturn_service_stat.stat.exists"
  118. - name: Ensure Matrix coturn paths don't exist
  119. file:
  120. path: "{{ matrix_coturn_base_path }}"
  121. state: absent
  122. when: "not matrix_coturn_enabled|bool"
  123. - name: Ensure coturn Docker image doesn't exist
  124. docker_image:
  125. name: "{{ matrix_coturn_docker_image }}"
  126. state: absent
  127. when: "not matrix_coturn_enabled|bool"