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.
 
 

157 líneas
6.3 KiB

  1. ---
  2. - name: Ensure Matrix Synapse paths exists
  3. file:
  4. path: "{{ item }}"
  5. state: directory
  6. mode: 0750
  7. owner: "{{ matrix_user_username }}"
  8. group: "{{ matrix_user_username }}"
  9. with_items:
  10. - "{{ matrix_synapse_base_path }}"
  11. - "{{ matrix_synapse_config_dir_path }}"
  12. - "{{ matrix_synapse_run_path }}"
  13. # We handle matrix_synapse_media_store_path below, not here,
  14. # because if it's using S3fs and it's already mounted (from before),
  15. # trying to chown/chmod it here will cause trouble.
  16. - name: Check Matrix Synapse media store path
  17. stat: path="{{ matrix_synapse_media_store_path }}"
  18. register: local_path_media_store_stat
  19. # This is separate and conditional, to ensure we don't execute it
  20. # if the path already exists (and is likely used by an s3fs mount).
  21. - name: Ensure Matrix media store path exists
  22. file:
  23. path: "{{ matrix_synapse_media_store_path }}"
  24. state: directory
  25. mode: 0750
  26. owner: "{{ matrix_user_username }}"
  27. group: "{{ matrix_user_username }}"
  28. when: "not local_path_media_store_stat.stat.exists"
  29. - name: Ensure Matrix Docker image is pulled
  30. docker_image:
  31. name: "{{ docker_matrix_image }}"
  32. - name: Check if a Matrix Synapse configuration exists
  33. stat:
  34. path: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  35. register: matrix_synapse_config_stat
  36. - name: Generate initial Matrix config
  37. docker_container:
  38. name: matrix-config
  39. image: "{{ docker_matrix_image }}"
  40. detach: no
  41. cleanup: yes
  42. command: generate
  43. env:
  44. SERVER_NAME: "{{ hostname_matrix }}"
  45. REPORT_STATS: "no"
  46. user: "{{ matrix_user_uid }}:{{ matrix_user_gid }}"
  47. volumes:
  48. - "{{ matrix_synapse_config_dir_path }}:/data"
  49. when: "not matrix_synapse_config_stat.stat.exists"
  50. - name: Ensure self-signed certificates are removed
  51. file:
  52. path: "{{ item }}"
  53. state: absent
  54. with_items:
  55. - "{{ matrix_synapse_config_dir_path }}/{{ hostname_matrix }}.tls.crt"
  56. - "{{ matrix_synapse_config_dir_path }}/{{ hostname_matrix }}.tls.key"
  57. - name: Augment Matrix log config
  58. lineinfile: "dest={{ matrix_synapse_config_dir_path }}/{{ hostname_matrix }}.log.config"
  59. args:
  60. regexp: "{{ item.regexp }}"
  61. line: '{{ item.line }}'
  62. with_items:
  63. - {"regexp": "^ filename:", "line": ' filename: /matrix-run/homeserver.log'}
  64. - {"regexp": "^ maxBytes:", "line": ' maxBytes: {{ matrix_max_log_file_size_mb * 1024 * 1024 }}'}
  65. - {"regexp": "^ backupCount:", "line": ' backupCount: {{ matrix_max_log_files_count }}'}
  66. - name: Augment Matrix config
  67. lineinfile: "dest={{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  68. args:
  69. regexp: "{{ item.regexp }}"
  70. line: '{{ item.line }}'
  71. with_items:
  72. - {"regexp": "^log_file:", "line": 'log_file: "/matrix-run/homeserver.log"'}
  73. - {"regexp": "^tls_certificate_path:", "line": 'tls_certificate_path: "/acmetool-certs/live/{{ hostname_matrix }}/fullchain"'}
  74. - {"regexp": "^tls_private_key_path:", "line": 'tls_private_key_path: "/acmetool-certs/live/{{ hostname_matrix }}/privkey"'}
  75. - {"regexp": "^server_name:", "line": 'server_name: "{{ hostname_identity }}"'}
  76. - {"regexp": "^turn_allow_guests:", "line": 'turn_allow_guests: False'}
  77. - {"regexp": "^url_preview_enabled:", "line": 'url_preview_enabled: True'}
  78. - {"regexp": "^max_upload_size:", "line": 'max_upload_size: "{{ matrix_max_upload_size_mb }}M"'}
  79. - {"regexp": "^media_store_path:", "line": 'media_store_path: "/matrix-media-store"'}
  80. - name: Augment Matrix config (specify URL previews blacklist)
  81. lineinfile: "dest={{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  82. args:
  83. regexp: "^url_preview_ip_range_blacklist:"
  84. line: 'url_preview_ip_range_blacklist: ["127.0.0.0/8", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "100.64.0.0/10", "169.254.0.0/16"]'
  85. insertafter: '^# url_preview_ip_range_blacklist:$'
  86. # We only wish to do this for the 8008 port and not for the 8448 port
  87. # (2nd instance of `x_forwarded` found in the config)
  88. - name: Augment Matrix config (mark 8008 plain traffic as forwarded)
  89. replace: "dest={{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  90. args:
  91. regexp: "8008((?:.|\n)*)x_forwarded(.*)"
  92. replace: '8008\g<1>x_forwarded: true'
  93. - name: Augment Matrix config (change database from SQLite to Postgres)
  94. lineinfile:
  95. dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  96. regexp: '(.*)name: "sqlite3"'
  97. line: '\1name: "psycopg2"'
  98. backrefs: yes
  99. - name: Augment Matrix config (set the Postgres connection parameters)
  100. replace:
  101. dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  102. regexp: '(.*)name: "psycopg2"((?:.|\n)*?)\n\n'
  103. replace: '\1name: "psycopg2"\n\1args:\n\1\1user: "{{ matrix_postgres_connection_username }}"\n\1\1password: "{{ matrix_postgres_connection_password }}"\n\1\1database: "{{ matrix_postgres_db_name }}"\n\1\1host: "{{ matrix_postgres_connection_hostname }}"\n\1\1cp_min: 5\n\1\1cp_max: 10\n\n'
  104. - name: Augment Matrix config (configure Coturn)
  105. lineinfile: "dest={{ matrix_synapse_config_dir_path }}/turnserver.conf"
  106. args:
  107. regexp: "^{{ item.variable }}="
  108. line: '{{ item.variable }}={{ item.value }}'
  109. with_items:
  110. - {'variable': 'min-port', 'value': "{{ matrix_coturn_turn_udp_min_port }}"}
  111. - {'variable': 'max-port', 'value': "{{ matrix_coturn_turn_udp_max_port }}"}
  112. - {'variable': 'external-ip', 'value': "{{ matrix_coturn_turn_external_ip_address }}"}
  113. - name: Allow access to Matrix ports in firewalld
  114. firewalld:
  115. port: "{{ item }}"
  116. state: enabled
  117. immediate: yes
  118. permanent: yes
  119. with_items:
  120. - '8448/tcp' # Matrix federation
  121. - '3478/tcp' # STUN
  122. - '3478/udp' # STUN
  123. - "{{ matrix_coturn_turn_udp_min_port }}-{{ matrix_coturn_turn_udp_max_port }}/udp" # TURN
  124. - name: Ensure matrix-synapse.service installed
  125. template:
  126. src: "{{ role_path }}/templates/systemd/matrix-synapse.service.j2"
  127. dest: "/etc/systemd/system/matrix-synapse.service"
  128. mode: 0644
  129. - name: Ensure matrix-synapse-register-user script created
  130. template:
  131. src: "{{ role_path }}/templates/usr-local-bin/matrix-synapse-register-user.j2"
  132. dest: "/usr/local/bin/matrix-synapse-register-user"
  133. mode: 0750
  134. - name: Ensure periodic restarting of Matrix is configured (for SSL renewal)
  135. template:
  136. src: "{{ role_path }}/templates/cron.d/matrix-periodic-restarter.j2"
  137. dest: "/etc/cron.d/matrix-periodic-restarter"
  138. mode: 0600