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

124 строки
4.2 KiB

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