Matrix Docker Ansible eploy
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

324 satır
18 KiB

  1. # SPDX-FileCopyrightText: 2026 Slavi Pantaleev
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - name: Verify matrix-client-element
  6. hosts: all
  7. become: true
  8. vars_files:
  9. - "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/vars.yml"
  10. - "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/playbook-context.yml"
  11. gather_facts: false
  12. tasks:
  13. # Load the shipped version independently of the scenario. The expected image
  14. # below is therefore advanced by the role's own version bump, not a test pin.
  15. - name: Load the role's defaults under a separate name
  16. ansible.builtin.include_vars:
  17. file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/main.yml"
  18. name: matrix_client_element_role_defaults
  19. - name: Wait for the matrix-client-element service to become active
  20. ansible.builtin.systemd_service:
  21. name: matrix-client-element.service
  22. register: matrix_client_element_service
  23. until: matrix_client_element_service.status.ActiveState == 'active'
  24. retries: 30
  25. delay: 5
  26. failed_when: false
  27. - name: Assert the service is active and has not restarted
  28. ansible.builtin.assert:
  29. that:
  30. - matrix_client_element_service.status.ActiveState == 'active'
  31. - matrix_client_element_service.status.NRestarts is defined
  32. - matrix_client_element_service.status.NRestarts | int == 0
  33. fail_msg: >-
  34. matrix-client-element.service is
  35. {{ matrix_client_element_service.status.ActiveState | default('unknown') }}
  36. after {{ matrix_client_element_service.status.NRestarts | default('?') }} restart(s)
  37. success_msg: "matrix-client-element.service is active and has not restarted"
  38. # Probe over the private container network. The role intentionally publishes
  39. # no host port, matching the path Traefik uses in a real deployment.
  40. - name: Fetch Element Web's root document
  41. ansible.builtin.command:
  42. argv:
  43. - docker
  44. - run
  45. - --rm
  46. - --network={{ matrix_client_element_container_network }}
  47. - "{{ molecule_shared_image_curl }}"
  48. - --silent
  49. - --show-error
  50. - --write-out
  51. - "\nHTTP_STATUS=%{http_code}"
  52. - "http://matrix-client-element:{{ matrix_client_element_container_port }}/"
  53. register: matrix_client_element_root_response
  54. changed_when: false
  55. until: "'HTTP_STATUS=200' in matrix_client_element_root_response.stdout"
  56. retries: 24
  57. delay: 5
  58. failed_when: false
  59. - name: Assert the root endpoint serves the Element application
  60. ansible.builtin.assert:
  61. that:
  62. - "'HTTP_STATUS=200' in matrix_client_element_root_response.stdout"
  63. - "'<title>Element' in matrix_client_element_root_response.stdout"
  64. fail_msg: >-
  65. Element Web did not serve its application root on the configured internal
  66. port ({{ matrix_client_element_root_response.stdout | default('no output') }})
  67. success_msg: "Element Web serves its application root on the configured internal port"
  68. - name: Fetch Element Web's served configuration
  69. ansible.builtin.command:
  70. argv:
  71. - docker
  72. - run
  73. - --rm
  74. - --network={{ matrix_client_element_container_network }}
  75. - "{{ molecule_shared_image_curl }}"
  76. - --silent
  77. - --show-error
  78. - --write-out
  79. - "\nHTTP_STATUS=%{http_code}"
  80. - "http://matrix-client-element:{{ matrix_client_element_container_port }}/config.json"
  81. register: matrix_client_element_served_config_response
  82. changed_when: false
  83. failed_when: false
  84. - name: Assert config.json is served successfully
  85. ansible.builtin.assert:
  86. that:
  87. - "'HTTP_STATUS=200' in matrix_client_element_served_config_response.stdout"
  88. fail_msg: >-
  89. Element Web did not serve config.json on the configured internal port
  90. ({{ matrix_client_element_served_config_response.stdout | default('no output') }})
  91. success_msg: "Element Web serves config.json on the configured internal port"
  92. - name: Read the rendered configuration
  93. ansible.builtin.slurp:
  94. src: "{{ matrix_client_element_data_path }}/config.json"
  95. register: matrix_client_element_rendered_config_file
  96. - name: Parse the served and rendered configurations
  97. ansible.builtin.set_fact:
  98. matrix_client_element_served_config: >-
  99. {{ matrix_client_element_served_config_response.stdout | regex_replace('HTTP_STATUS=[0-9]+$', '') | trim | from_json }}
  100. matrix_client_element_rendered_config: >-
  101. {{ matrix_client_element_rendered_config_file.content | b64decode | from_json }}
  102. - name: Assert the served configuration is the file the role rendered
  103. ansible.builtin.assert:
  104. that:
  105. - matrix_client_element_served_config == matrix_client_element_rendered_config
  106. fail_msg: "The config.json served by Element differs from the file the role rendered"
  107. success_msg: "Element serves the exact configuration the role rendered"
  108. - name: Assert the rendered configuration carries the homeserver identity
  109. ansible.builtin.assert:
  110. that:
  111. - matrix_client_element_rendered_config.default_server_config['m.homeserver'].base_url == matrix_client_element_default_hs_url
  112. - matrix_client_element_rendered_config.default_server_config['m.homeserver'].server_name == matrix_client_element_default_server_name
  113. - matrix_client_element_rendered_config.default_server_config['m.identity_server'].base_url == matrix_client_element_default_is_url
  114. fail_msg: "The rendered configuration does not carry the scenario's homeserver identity"
  115. success_msg: "The rendered configuration carries the scenario's homeserver identity"
  116. - name: Assert the rendered configuration carries the appearance and client behavior
  117. ansible.builtin.assert:
  118. that:
  119. - matrix_client_element_rendered_config.brand == matrix_client_element_brand
  120. - matrix_client_element_rendered_config.default_theme == matrix_client_element_default_theme
  121. - matrix_client_element_rendered_config.disable_custom_urls == matrix_client_element_disable_custom_urls
  122. - matrix_client_element_rendered_config.disable_guests == matrix_client_element_disable_guests
  123. - matrix_client_element_rendered_config.default_country_code == matrix_client_element_default_country_code
  124. - matrix_client_element_rendered_config.setting_defaults.custom_themes[0].name == 'Molecule Midnight'
  125. - matrix_client_element_rendered_config.branding.auth_footer_links[0].text == 'Molecule help'
  126. - matrix_client_element_rendered_config.branding.auth_header_logo_url == matrix_client_element_branding_auth_header_logo_url
  127. fail_msg: "The rendered configuration does not carry the scenario's appearance and client behavior"
  128. success_msg: "The rendered configuration carries the scenario's appearance and client behavior"
  129. - name: Assert the rendered configuration carries the integration endpoints
  130. ansible.builtin.assert:
  131. that:
  132. - matrix_client_element_rendered_config.integrations_ui_url == matrix_client_element_integrations_ui_url
  133. - matrix_client_element_rendered_config.integrations_rest_url == matrix_client_element_integrations_rest_url
  134. - matrix_client_element_rendered_config.integrations_widgets_urls == matrix_client_element_integrations_widgets_urls
  135. - matrix_client_element_rendered_config.integrations_jitsi_widget_url == matrix_client_element_integrations_jitsi_widget_url
  136. fail_msg: "The rendered configuration does not carry the scenario's integration endpoints"
  137. success_msg: "The rendered configuration carries the scenario's integration endpoints"
  138. - name: Assert the rendered configuration carries the feature and Element Call settings
  139. ansible.builtin.assert:
  140. that:
  141. - matrix_client_element_rendered_config.features.feature_group_calls == true
  142. - matrix_client_element_rendered_config.features.feature_oidc_native_flow == true
  143. - matrix_client_element_rendered_config.features.feature_molecule_scenario == 'labs'
  144. - matrix_client_element_rendered_config.element_call.url == matrix_client_element_element_call_url
  145. - matrix_client_element_rendered_config.element_call.participant_limit == matrix_client_element_element_call_participant_limit
  146. - matrix_client_element_rendered_config.element_call.brand == matrix_client_element_element_call_brand
  147. # Element Web documents the omitted use_exclusively setting as false;
  148. # the role deliberately leaves this default-valued key out of lean JSON.
  149. - "'use_exclusively' not in matrix_client_element_rendered_config.element_call"
  150. fail_msg: "The rendered configuration does not carry the scenario's feature and Element Call settings"
  151. success_msg: "The rendered configuration carries the scenario's feature and Element Call settings"
  152. - name: Assert the configuration extension was merged structurally
  153. ansible.builtin.assert:
  154. that:
  155. - matrix_client_element_rendered_config.disable_3pid_login == true
  156. - matrix_client_element_rendered_config.disable_login_language_selector == true
  157. - matrix_client_element_rendered_config.molecule_extension.enabled == true
  158. - matrix_client_element_rendered_config.molecule_extension.marker == 'element-config-extension'
  159. - matrix_client_element_rendered_config.molecule_extension.sequence == 42
  160. fail_msg: "The configuration extension was not merged under the expected keys"
  161. success_msg: "The configuration extension was merged structurally"
  162. - name: Read the environment file the role rendered
  163. ansible.builtin.slurp:
  164. src: "{{ matrix_client_element_data_path }}/env"
  165. register: matrix_client_element_env_file
  166. - name: Initialize the parsed environment
  167. ansible.builtin.set_fact:
  168. matrix_client_element_env_parsed: {}
  169. - name: Parse the rendered environment
  170. ansible.builtin.set_fact:
  171. matrix_client_element_env_parsed: >-
  172. {{ matrix_client_element_env_parsed | combine({item.split('=', 1)[0]: item.split('=', 1)[1]}) }}
  173. loop: "{{ (matrix_client_element_env_file.content | b64decode).splitlines() | reject('equalto', '') }}"
  174. when: "'=' in item"
  175. no_log: true
  176. - name: Inspect the running Element container
  177. ansible.builtin.command:
  178. argv:
  179. - docker
  180. - container
  181. - inspect
  182. - matrix-client-element
  183. register: matrix_client_element_container_inspect_command
  184. changed_when: false
  185. - name: Parse the running container inspection
  186. ansible.builtin.set_fact:
  187. matrix_client_element_container: "{{ (matrix_client_element_container_inspect_command.stdout | from_json)[0] }}"
  188. - name: Assert the rendered environment file carries the scenario values
  189. ansible.builtin.assert:
  190. that:
  191. - matrix_client_element_env_parsed.ELEMENT_WEB_PORT == matrix_client_element_container_port | string
  192. - matrix_client_element_env_parsed.MOLECULE_ELEMENT_MARKER == 'environment-reached'
  193. fail_msg: "The parsed environment file does not carry the scenario's values"
  194. success_msg: "The parsed environment file carries the scenario's values"
  195. - name: Assert the configured environment reached the running container
  196. ansible.builtin.assert:
  197. that:
  198. - "('ELEMENT_WEB_PORT=' ~ (matrix_client_element_container_port | string)) in matrix_client_element_container.Config.Env"
  199. - "'MOLECULE_ELEMENT_MARKER=environment-reached' in matrix_client_element_container.Config.Env"
  200. fail_msg: "The running container environment does not carry the scenario's values"
  201. success_msg: "The configured environment reached the running container"
  202. - name: Read the labels file the role rendered
  203. ansible.builtin.slurp:
  204. src: "{{ matrix_client_element_data_path }}/labels"
  205. register: matrix_client_element_labels_file
  206. - name: Initialize the parsed labels
  207. ansible.builtin.set_fact:
  208. matrix_client_element_labels_parsed: {}
  209. - name: Parse the rendered labels
  210. ansible.builtin.set_fact:
  211. matrix_client_element_labels_parsed: >-
  212. {{ matrix_client_element_labels_parsed | combine({item.split('=', 1)[0]: item.split('=', 1)[1]}) }}
  213. loop: "{{ (matrix_client_element_labels_file.content | b64decode).splitlines() | reject('equalto', '') }}"
  214. when: "'=' in item"
  215. no_log: true
  216. - name: Assert the rendered labels carry the routing configuration
  217. ansible.builtin.assert:
  218. that:
  219. - matrix_client_element_labels_parsed['traefik.enable'] == 'true'
  220. - matrix_client_element_labels_parsed['traefik.docker.network'] == matrix_client_element_container_network
  221. - matrix_client_element_labels_parsed['traefik.http.services.matrix-client-element.loadbalancer.server.port'] == matrix_client_element_container_port | string
  222. - "('Host(`' ~ matrix_client_element_hostname ~ '`)') in matrix_client_element_labels_parsed['traefik.http.routers.matrix-client-element.rule']"
  223. - "('PathPrefix(`' ~ matrix_client_element_path_prefix ~ '`)') in matrix_client_element_labels_parsed['traefik.http.routers.matrix-client-element.rule']"
  224. - matrix_client_element_labels_parsed['traefik.http.routers.matrix-client-element.priority'] == '73'
  225. - matrix_client_element_labels_parsed['traefik.http.routers.matrix-client-element.tls'] == 'false'
  226. - "matrix_client_element_container_labels_traefik_compression_middleware_name in matrix_client_element_labels_parsed['traefik.http.routers.matrix-client-element.middlewares']"
  227. - matrix_client_element_labels_parsed['traefik.http.middlewares.matrix-client-element-add-headers.headers.customresponseheaders.X-Molecule-Element'] == 'rendered'
  228. - matrix_client_element_labels_parsed['molecule.scenario'] == 'matrix-client-element'
  229. fail_msg: "The rendered labels do not carry the scenario's routing configuration"
  230. success_msg: "The rendered labels carry the scenario's routing configuration"
  231. - name: Assert the rendered labels are attached to the running container
  232. ansible.builtin.assert:
  233. that:
  234. - matrix_client_element_container.Config.Labels['traefik.enable'] == 'true'
  235. - matrix_client_element_container.Config.Labels['traefik.docker.network'] == matrix_client_element_container_network
  236. - matrix_client_element_container.Config.Labels['traefik.http.services.matrix-client-element.loadbalancer.server.port'] == matrix_client_element_container_port | string
  237. - matrix_client_element_container.Config.Labels['molecule.scenario'] == 'matrix-client-element'
  238. fail_msg: "The running container does not carry the labels the role rendered"
  239. success_msg: "The running container carries the labels the role rendered"
  240. - name: Assert the running container uses the exact image and version the role pins
  241. ansible.builtin.assert:
  242. that:
  243. - matrix_client_element_container.Config.Image == matrix_client_element_expected_image
  244. fail_msg: >-
  245. The running container uses {{ matrix_client_element_container.Config.Image }},
  246. expected {{ matrix_client_element_expected_image }}
  247. success_msg: "The running container uses the exact image and version defaults/main.yml pins"
  248. vars:
  249. matrix_client_element_expected_image: >-
  250. {{ matrix_client_element_role_defaults.matrix_client_element_container_image_registry_prefix_upstream_default }}element-hq/element-web:{{ matrix_client_element_role_defaults.matrix_client_element_version }}
  251. - name: Assert the running container uses the configured UID and GID
  252. ansible.builtin.assert:
  253. that:
  254. - matrix_client_element_container.Config.User == (matrix_user_uid | string) ~ ':' ~ (matrix_user_gid | string)
  255. fail_msg: >-
  256. The running container uses {{ matrix_client_element_container.Config.User }},
  257. expected {{ matrix_user_uid }}:{{ matrix_user_gid }}
  258. success_msg: "The running container uses the configured UID and GID"
  259. - name: Assert the running container has a read-only root filesystem
  260. ansible.builtin.assert:
  261. that:
  262. - matrix_client_element_container.HostConfig.ReadonlyRootfs == true
  263. fail_msg: "The running container's root filesystem is writable"
  264. success_msg: "The running container has a read-only root filesystem"
  265. - name: Assert all intended writable paths are tmpfs mounts
  266. ansible.builtin.assert:
  267. that:
  268. - "'/tmp' in matrix_client_element_container.HostConfig.Tmpfs"
  269. - "'/var/cache/nginx' in matrix_client_element_container.HostConfig.Tmpfs"
  270. - "'/var/run' in matrix_client_element_container.HostConfig.Tmpfs"
  271. - "'/tmp/element-web-config' in matrix_client_element_container.HostConfig.Tmpfs"
  272. - "'/etc/nginx/conf.d' in matrix_client_element_container.HostConfig.Tmpfs"
  273. fail_msg: "The running container is missing one or more intended tmpfs mounts"
  274. success_msg: "All intended writable paths are tmpfs mounts"
  275. - name: Assert the running container is attached only to its dedicated network
  276. ansible.builtin.assert:
  277. that:
  278. - matrix_client_element_container.NetworkSettings.Networks.keys() | list | length == 1
  279. - matrix_client_element_container_network in matrix_client_element_container.NetworkSettings.Networks
  280. fail_msg: >-
  281. The running container is attached to unexpected networks:
  282. {{ matrix_client_element_container.NetworkSettings.Networks.keys() | list }}
  283. success_msg: "The running container is attached only to its dedicated network"
  284. - name: Assert the running container publishes no host ports
  285. ansible.builtin.assert:
  286. that:
  287. - matrix_client_element_container.HostConfig.PortBindings | default({}, true) | length == 0
  288. fail_msg: "The running container unexpectedly publishes a host port"
  289. success_msg: "The running container publishes no host ports"