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.
 
 

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