Matrix Docker Ansible eploy
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

137 righe
4.4 KiB

  1. ---
  2. # This will throw a Permission Denied error if already mounted using fuse
  3. - name: Check Matrix Synapse media store path
  4. stat:
  5. path: "{{ matrix_synapse_media_store_path }}"
  6. register: local_path_media_store_stat
  7. ignore_errors: yes
  8. # This is separate and conditional, to ensure we don't execute it
  9. # if the path already exists or we failed to check, because it's mounted using fuse.
  10. - name: Ensure Matrix media store path exists
  11. file:
  12. path: "{{ matrix_synapse_media_store_path }}"
  13. state: directory
  14. mode: 0750
  15. owner: "{{ matrix_user_username }}"
  16. group: "{{ matrix_user_username }}"
  17. when: "not local_path_media_store_stat.failed and not local_path_media_store_stat.stat.exists"
  18. - name: Ensure Matrix Docker image is pulled
  19. docker_image:
  20. name: "{{ matrix_synapse_docker_image }}"
  21. - name: Check if a Matrix Synapse configuration exists
  22. stat:
  23. path: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  24. register: matrix_synapse_config_stat
  25. # We do this mostly so that the keys would get generated.
  26. # We'll replace the rest of the configuration with our own templates below.
  27. - name: Generate initial Matrix config
  28. docker_container:
  29. name: matrix-config
  30. image: "{{ matrix_synapse_docker_image }}"
  31. detach: no
  32. cleanup: yes
  33. command: generate
  34. env:
  35. SYNAPSE_CONFIG_PATH: "/data/homeserver.yaml"
  36. SYNAPSE_SERVER_NAME: "{{ hostname_matrix }}"
  37. SYNAPSE_REPORT_STATS: "no"
  38. user: "{{ matrix_user_uid }}:{{ matrix_user_gid }}"
  39. cap_drop: ['all']
  40. volumes:
  41. - "{{ matrix_synapse_config_dir_path }}:/data"
  42. when: "not matrix_synapse_config_stat.stat.exists"
  43. - name: Ensure Matrix homeserver config installed
  44. template:
  45. src: "{{ matrix_synapse_template_synapse_homeserver }}"
  46. dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  47. mode: 0644
  48. - name: Ensure Matrix log config installed
  49. template:
  50. src: "{{ matrix_synapse_template_synapse_log }}"
  51. dest: "{{ matrix_synapse_config_dir_path }}/{{ hostname_matrix }}.log.config"
  52. mode: 0644
  53. #
  54. # To make Synapse 0.99 happy, we need to generate a valid (self-signed is OK) certificate file that we provide to it.
  55. # It won't be used for anything important, but it needs to be there.
  56. # See https://github.com/matrix-org/synapse/issues/4554
  57. #
  58. # Previously, Synapse would generate such certificate files and actually use them.
  59. # So existing installations already have them.
  60. #
  61. - name: Check if Synapse certificate exists
  62. stat:
  63. path: "{{ matrix_synapse_config_dir_path }}/{{ hostname_matrix }}.tls.crt"
  64. register: matrix_synapse_certificate_stat
  65. - name: Ensure OpenSSL installed (RedHat)
  66. yum:
  67. name:
  68. - openssl
  69. state: present
  70. update_cache: no
  71. when: "not matrix_synapse_certificate_stat.stat.exists and ansible_os_family == 'RedHat'"
  72. - name: Ensure OpenSSL installed (Debian)
  73. apt:
  74. name:
  75. - openssl
  76. state: present
  77. update_cache: no
  78. when: "not matrix_synapse_certificate_stat.stat.exists and ansible_os_family == 'Debian'"
  79. # The proper way to do this is by using a sequence of
  80. # `openssl_privatekey`, `openssl_csr` and `openssl_certificate`.
  81. #
  82. # Unfortunately, `openssl_csr` and `openssl_certificate` require `PyOpenSSL>=0.15` to work,
  83. # which is not available on CentOS 7 (at least).
  84. #
  85. # We'll do it in a more manual way.
  86. - name: Generate SSL certificate
  87. command: |
  88. openssl req -x509 \
  89. -sha256 \
  90. -newkey rsa:4096 \
  91. -nodes \
  92. -subj "/CN={{ hostname_matrix }}" \
  93. -keyout {{ matrix_synapse_config_dir_path }}/{{ hostname_matrix }}.tls.key \
  94. -out {{ matrix_synapse_config_dir_path }}/{{ hostname_matrix }}.tls.crt \
  95. -days 3650
  96. become: true
  97. become_user: "{{ matrix_user_username }}"
  98. when: "not matrix_synapse_certificate_stat.stat.exists"
  99. #
  100. # End of tasks related to making Synapse 0.99 happy.
  101. #
  102. - name: Ensure matrix-synapse.service installed
  103. template:
  104. src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse.service.j2"
  105. dest: "/etc/systemd/system/matrix-synapse.service"
  106. mode: 0644
  107. - name: Ensure matrix-synapse-register-user script created
  108. template:
  109. src: "{{ role_path }}/templates/synapse/usr-local-bin/matrix-synapse-register-user.j2"
  110. dest: "/usr/local/bin/matrix-synapse-register-user"
  111. mode: 0750
  112. - name: Allow access to Matrix ports in firewalld
  113. firewalld:
  114. port: "{{ item }}"
  115. state: enabled
  116. immediate: yes
  117. permanent: yes
  118. with_items:
  119. - '8448/tcp' # Matrix federation
  120. when: ansible_os_family == 'RedHat'