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.
 
 

153 rivejä
5.1 KiB

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