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

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