Matrix Docker Ansible eploy
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

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