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.
 
 

119 lines
4.2 KiB

  1. ---
  2. - name: Ensure Matrix Synapse data path exists
  3. file:
  4. path: "{{ matrix_synapse_data_path }}"
  5. state: directory
  6. mode: 0750
  7. owner: "{{ matrix_user_username }}"
  8. group: "{{ matrix_user_username }}"
  9. - name: Ensure Matrix Docker image is pulled
  10. docker_image:
  11. name: "{{ docker_matrix_image }}"
  12. - name: Generate initial Matrix config
  13. docker_container:
  14. name: matrix-config
  15. image: "{{ docker_matrix_image }}"
  16. detach: no
  17. cleanup: yes
  18. command: generate
  19. env:
  20. SERVER_NAME: "{{ hostname_matrix }}"
  21. REPORT_STATS: "no"
  22. user: "{{ matrix_user_uid }}:{{ matrix_user_gid }}"
  23. volumes:
  24. - "{{ matrix_synapse_data_path }}:/data"
  25. - name: Augment Matrix config (configure SSL fullchain location)
  26. lineinfile: "dest={{ matrix_synapse_data_path }}/homeserver.yaml"
  27. args:
  28. regexp: "^tls_certificate_path:"
  29. line: 'tls_certificate_path: "/acmetool-certs/live/{{ hostname_matrix }}/fullchain"'
  30. - name: Augment Matrix config (configure SSL private key location)
  31. lineinfile: "dest={{ matrix_synapse_data_path }}/homeserver.yaml"
  32. args:
  33. regexp: "^tls_private_key_path:"
  34. line: 'tls_private_key_path: "/acmetool-certs/live/{{ hostname_matrix }}/privkey"'
  35. - name: Augment Matrix config (configure server name)
  36. lineinfile: "dest={{ matrix_synapse_data_path }}/homeserver.yaml"
  37. args:
  38. regexp: "^server_name:"
  39. line: 'server_name: "{{ hostname_identity }}"'
  40. - name: Augment Matrix config (disable TURN for guests)
  41. lineinfile: "dest={{ matrix_synapse_data_path }}/homeserver.yaml"
  42. args:
  43. regexp: "^turn_allow_guests:"
  44. line: 'turn_allow_guests: False'
  45. - name: Augment Matrix config (enable URL previews)
  46. lineinfile: "dest={{ matrix_synapse_data_path }}/homeserver.yaml"
  47. args:
  48. regexp: "^url_preview_enabled:"
  49. line: 'url_preview_enabled: True'
  50. - name: Augment Matrix config (specify URL previews blacklist)
  51. lineinfile: "dest={{ matrix_synapse_data_path }}/homeserver.yaml"
  52. args:
  53. regexp: "^url_preview_ip_range_blacklist:"
  54. 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"]'
  55. insertafter: '^# url_preview_ip_range_blacklist:$'
  56. - name: Augment Matrix config (change database from SQLite to Postgres)
  57. lineinfile:
  58. dest: "{{ matrix_synapse_data_path }}/homeserver.yaml"
  59. regexp: '(.*)name: "sqlite3"'
  60. line: '\1name: "psycopg2"'
  61. backrefs: yes
  62. - name: Augment Matrix config (add the Postgres connection parameters)
  63. lineinfile:
  64. dest: "{{ matrix_synapse_data_path }}/homeserver.yaml"
  65. regexp: '(.*)database: "(.*)homeserver.db"'
  66. line: '\1user: "{{ matrix_postgres_connection_username }}"\n\1password: "{{ matrix_postgres_connection_password }}"\n\1database: "homeserver"\n\1host: "postgres"\n\1cp_min: 5\n\1cp_max: 10'
  67. backrefs: yes
  68. - name: Augment Matrix config (configure Coturn)
  69. lineinfile: "dest={{ matrix_synapse_data_path }}/turnserver.conf"
  70. args:
  71. regexp: "^{{ item.variable }}="
  72. line: '{{ item.variable }}={{ item.value }}'
  73. with_items:
  74. - {'variable': 'min-port', 'value': "{{ matrix_coturn_turn_udp_min_port }}"}
  75. - {'variable': 'max-port', 'value': "{{ matrix_coturn_turn_udp_max_port }}"}
  76. - {'variable': 'external-ip', 'value': "{{ matrix_coturn_turn_external_ip_address }}"}
  77. - name: Allow access to Matrix ports in firewalld
  78. firewalld:
  79. port: "{{ item }}"
  80. state: enabled
  81. immediate: yes
  82. permanent: yes
  83. with_items:
  84. - '8448/tcp' # Matrix federation
  85. - '3478/tcp' # STUN
  86. - '3478/udp' # STUN
  87. - "{{ matrix_coturn_turn_udp_min_port }}-{{ matrix_coturn_turn_udp_max_port }}/udp" # TURN
  88. - name: Ensure matrix-synapse.service installed
  89. template:
  90. src: "{{ role_path }}/templates/systemd/matrix-synapse.service.j2"
  91. dest: "/etc/systemd/system/matrix-synapse.service"
  92. mode: 0644
  93. - name: Ensure matrix-synapse-register-user script created
  94. template:
  95. src: "{{ role_path }}/templates/usr-local-bin/matrix-synapse-register-user.j2"
  96. dest: "/usr/local/bin/matrix-synapse-register-user"
  97. mode: 0750
  98. - name: Ensure periodic restarting of Matrix is configured (for SSL renewal)
  99. template:
  100. src: "{{ role_path }}/templates/cron.d/matrix-periodic-restarter.j2"
  101. dest: "/etc/cron.d/matrix-periodic-restarter"
  102. mode: 0600