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.
 
 
 

442 line
25 KiB

  1. # SPDX-FileCopyrightText: 2026 Slavi Pantaleev
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - name: Verify matrix-bot-honoroit
  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. vars:
  12. matrix_bot_honoroit_health_body: "{{ matrix_bot_honoroit_health.stdout_lines[:-1] | join('\n') }}"
  13. matrix_bot_honoroit_metrics_body: "{{ matrix_bot_honoroit_metrics.stdout_lines[:-1] | join('\n') }}"
  14. matrix_bot_honoroit_metrics_lines: "{{ matrix_bot_honoroit_metrics_body.splitlines() | select | list }}"
  15. matrix_bot_honoroit_rendered_env_lines: >-
  16. {{ (matrix_bot_honoroit_env_file.content | b64decode).splitlines()
  17. | select('match', '^[A-Z0-9_]+=') | list }}
  18. matrix_bot_honoroit_rendered_env: >-
  19. {{ dict(matrix_bot_honoroit_rendered_env_lines | map('split', '=', 1)) }}
  20. matrix_bot_honoroit_rendered_labels_lines: >-
  21. {{ (matrix_bot_honoroit_labels_file.content | b64decode).splitlines()
  22. | select('match', '^[A-Za-z0-9_.-]+=') | list }}
  23. matrix_bot_honoroit_rendered_labels: >-
  24. {{ dict(matrix_bot_honoroit_rendered_labels_lines | map('split', '=', 1)) }}
  25. matrix_bot_honoroit_runtime: "{{ (matrix_bot_honoroit_container_inspect.stdout | from_json) | first }}"
  26. matrix_bot_honoroit_runtime_env: "{{ dict(matrix_bot_honoroit_runtime.Config.Env | map('split', '=', 1)) }}"
  27. matrix_bot_honoroit_data_mounts: >-
  28. {{ matrix_bot_honoroit_runtime.Mounts | selectattr('Destination', 'equalto', '/data') | list }}
  29. gather_facts: false
  30. tasks:
  31. - name: Load the role's defaults under a separate name
  32. ansible.builtin.include_vars:
  33. file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/main.yml"
  34. name: matrix_bot_honoroit_role_defaults
  35. - name: Wait for the matrix-bot-honoroit service to become active
  36. ansible.builtin.systemd_service:
  37. name: matrix-bot-honoroit.service
  38. register: matrix_bot_honoroit_service
  39. until: matrix_bot_honoroit_service.status.ActiveState == 'active'
  40. retries: 30
  41. delay: 5
  42. failed_when: false
  43. - name: Assert the service is active and has not restarted
  44. ansible.builtin.assert:
  45. that:
  46. - matrix_bot_honoroit_service.status.ActiveState == 'active'
  47. - matrix_bot_honoroit_service.status.NRestarts is defined
  48. - matrix_bot_honoroit_service.status.NRestarts | int == 0
  49. fail_msg: >-
  50. matrix-bot-honoroit.service is
  51. {{ matrix_bot_honoroit_service.status.ActiveState | default('unknown') }} after
  52. {{ matrix_bot_honoroit_service.status.NRestarts | default('?') }} restart(s)
  53. success_msg: "matrix-bot-honoroit.service is active and has not restarted"
  54. - name: Wait for Honoroit's health API
  55. ansible.builtin.command:
  56. argv:
  57. - docker
  58. - run
  59. - --rm
  60. - --network={{ matrix_bot_honoroit_container_network }}
  61. - "{{ molecule_shared_image_curl }}"
  62. - --silent
  63. - --show-error
  64. - --write-out
  65. - "\nHTTP_STATUS=%{http_code}"
  66. - "http://matrix-bot-honoroit:{{ matrix_bot_honoroit_container_port }}/_health"
  67. register: matrix_bot_honoroit_health
  68. changed_when: false
  69. until: "'HTTP_STATUS=200' in matrix_bot_honoroit_health.stdout"
  70. retries: 24
  71. delay: 5
  72. failed_when: false
  73. - name: Assert the configured health API is live and structurally valid
  74. ansible.builtin.assert:
  75. that:
  76. - matrix_bot_honoroit_health.rc == 0
  77. - matrix_bot_honoroit_health.stdout_lines[-1] == 'HTTP_STATUS=200'
  78. - "matrix_bot_honoroit_health_body | from_json == {'status': 'ok'}"
  79. fail_msg: >-
  80. Honoroit's health API did not answer with its expected JSON
  81. ({{ matrix_bot_honoroit_health.stdout | default('no output') }})
  82. success_msg: "Honoroit's live health API answers with its structured status"
  83. - name: Ask the metrics endpoint without credentials
  84. ansible.builtin.command:
  85. argv:
  86. - docker
  87. - run
  88. - --rm
  89. - --network={{ matrix_bot_honoroit_container_network }}
  90. - "{{ molecule_shared_image_curl }}"
  91. - --silent
  92. - --output
  93. - /dev/null
  94. - --write-out
  95. - "HTTP_STATUS=%{http_code}"
  96. - "http://matrix-bot-honoroit:{{ matrix_bot_honoroit_container_port }}/metrics"
  97. register: matrix_bot_honoroit_unauthenticated_metrics
  98. changed_when: false
  99. failed_when: false
  100. - name: Assert the metrics endpoint requires authentication
  101. ansible.builtin.assert:
  102. that:
  103. - matrix_bot_honoroit_unauthenticated_metrics.rc == 0
  104. - matrix_bot_honoroit_unauthenticated_metrics.stdout == 'HTTP_STATUS=401'
  105. fail_msg: "Honoroit's metrics endpoint did not reject an unauthenticated request"
  106. success_msg: "Honoroit's metrics endpoint rejects unauthenticated requests"
  107. - name: Ask the metrics endpoint with incorrect credentials
  108. ansible.builtin.command:
  109. argv:
  110. - docker
  111. - run
  112. - --rm
  113. - --network={{ matrix_bot_honoroit_container_network }}
  114. - "{{ molecule_shared_image_curl }}"
  115. - --silent
  116. - --user
  117. - molecule-metrics-user:incorrect-molecule-password
  118. - --output
  119. - /dev/null
  120. - --write-out
  121. - "HTTP_STATUS=%{http_code}"
  122. - "http://matrix-bot-honoroit:{{ matrix_bot_honoroit_container_port }}/metrics"
  123. register: matrix_bot_honoroit_wrong_metrics_credentials
  124. changed_when: false
  125. failed_when: false
  126. - name: Assert the metrics endpoint rejects incorrect credentials
  127. ansible.builtin.assert:
  128. that:
  129. - matrix_bot_honoroit_wrong_metrics_credentials.rc == 0
  130. - matrix_bot_honoroit_wrong_metrics_credentials.stdout == 'HTTP_STATUS=401'
  131. fail_msg: "Honoroit's metrics endpoint accepted incorrect credentials"
  132. success_msg: "Honoroit's metrics endpoint rejects incorrect credentials"
  133. - name: Ask the metrics endpoint with the configured credentials
  134. ansible.builtin.command:
  135. argv:
  136. - docker
  137. - run
  138. - --rm
  139. - --network={{ matrix_bot_honoroit_container_network }}
  140. - "{{ molecule_shared_image_curl }}"
  141. - --silent
  142. - --show-error
  143. - --user
  144. - molecule-metrics-user:molecule_metrics_password_c9ed32
  145. - --write-out
  146. - "\nHTTP_STATUS=%{http_code}"
  147. - "http://matrix-bot-honoroit:{{ matrix_bot_honoroit_container_port }}/metrics"
  148. register: matrix_bot_honoroit_metrics
  149. changed_when: false
  150. failed_when: false
  151. - name: Assert configured credentials unlock genuine Prometheus metrics
  152. ansible.builtin.assert:
  153. that:
  154. - matrix_bot_honoroit_metrics.rc == 0
  155. - matrix_bot_honoroit_metrics.stdout_lines[-1] == 'HTTP_STATUS=200'
  156. - matrix_bot_honoroit_metrics_lines | select('match', '^honoroit_messages_operator [0-9]+$') | list | length == 1
  157. - matrix_bot_honoroit_metrics_lines | select('match', '^honoroit_messages_total [0-9]+$') | list | length == 1
  158. - matrix_bot_honoroit_metrics_lines | select('match', '^honoroit_request_done [0-9]+$') | list | length == 1
  159. - matrix_bot_honoroit_metrics_lines | select('match', '^honoroit_request_new [0-9]+$') | list | length == 1
  160. fail_msg: >-
  161. Configured credentials did not unlock Honoroit's Prometheus metrics
  162. ({{ matrix_bot_honoroit_metrics.stdout | default('no output') }})
  163. success_msg: "Configured credentials unlock Honoroit's Prometheus metrics"
  164. - name: Read the environment file the role rendered
  165. ansible.builtin.slurp:
  166. src: "{{ matrix_bot_honoroit_config_path }}/env"
  167. register: matrix_bot_honoroit_env_file
  168. - name: Assert the parsed environment contains the Matrix and Postgres wiring
  169. ansible.builtin.assert:
  170. that:
  171. - matrix_bot_honoroit_rendered_env.HONOROIT_LOGIN == matrix_bot_honoroit_login
  172. - matrix_bot_honoroit_rendered_env.HONOROIT_PASSWORD == matrix_bot_honoroit_password
  173. - matrix_bot_honoroit_rendered_env.HONOROIT_HOMESERVER == matrix_bot_honoroit_homeserver
  174. - matrix_bot_honoroit_rendered_env.HONOROIT_ROOMID == matrix_bot_honoroit_roomid
  175. - matrix_bot_honoroit_rendered_env.HONOROIT_DB_DIALECT == 'postgres'
  176. - matrix_bot_honoroit_rendered_env.HONOROIT_DB_DSN == 'postgres://molecule_honoroit_user:molecule_honoroit_password_8c45d1@matrix-postgres-molecule:5432/molecule_honoroit_database?sslmode=disable'
  177. fail_msg: "The parsed environment lost the scenario's Matrix or Postgres wiring"
  178. success_msg: "The parsed environment carries the scenario's Matrix and Postgres wiring"
  179. - name: Assert the parsed environment contains non-default bot behavior
  180. ansible.builtin.assert:
  181. that:
  182. - matrix_bot_honoroit_rendered_env.HONOROIT_PREFIX == '!molecule-help'
  183. - matrix_bot_honoroit_rendered_env.HONOROIT_NOENCRYPTIONWARNING | lower == 'true'
  184. - matrix_bot_honoroit_rendered_env.HONOROIT_LOGLEVEL == 'DEBUG'
  185. - matrix_bot_honoroit_rendered_env.HONOROIT_CACHESIZE == '317'
  186. - matrix_bot_honoroit_rendered_env.HONOROIT_IGNORENOTHREAD | lower == 'true'
  187. - matrix_bot_honoroit_rendered_env.HONOROIT_IGNOREDROOMS == '!molecule-ignored-one:molecule.local !molecule-ignored-two:molecule.local'
  188. - matrix_bot_honoroit_rendered_env.HONOROIT_ALLOWEDUSERS == '@support-*:molecule.local @operator:molecule.local'
  189. - matrix_bot_honoroit_rendered_env.HONOROIT_TEXT_PREFIX_OPEN == '[MOLECULE OPEN]'
  190. - matrix_bot_honoroit_rendered_env.HONOROIT_TEXT_PREFIX_DONE == '[MOLECULE DONE]'
  191. - matrix_bot_honoroit_rendered_env.HONOROIT_TEXT_GREETINGS == 'Molecule helpdesk greeting'
  192. - matrix_bot_honoroit_rendered_env.HONOROIT_TEXT_DONE == 'Molecule helpdesk completion'
  193. fail_msg: "The parsed environment lost non-default Honoroit behavior"
  194. success_msg: "The parsed environment carries non-default Honoroit behavior"
  195. - name: Assert the parsed environment contains metrics auth and extension values
  196. ansible.builtin.assert:
  197. that:
  198. - matrix_bot_honoroit_rendered_env.HONOROIT_AUTH_METRICS_LOGIN == 'molecule-metrics-user'
  199. - matrix_bot_honoroit_rendered_env.HONOROIT_AUTH_METRICS_PASSWORD == 'molecule_metrics_password_c9ed32'
  200. - matrix_bot_honoroit_rendered_env.HONOROIT_PORT == ':' ~ (matrix_bot_honoroit_container_port | string)
  201. - matrix_bot_honoroit_rendered_env.MOLECULE_HONOROIT_MARKER == 'role-rendered-environment'
  202. fail_msg: "The parsed environment lost the metrics auth or extension values"
  203. success_msg: "The parsed environment carries metrics auth and extension values"
  204. - name: List the tables Honoroit created in Postgres
  205. ansible.builtin.command:
  206. argv:
  207. - docker
  208. - exec
  209. - matrix-postgres-molecule
  210. - psql
  211. - --username={{ matrix_bot_honoroit_database_username }}
  212. - --dbname={{ matrix_bot_honoroit_database_name }}
  213. - --tuples-only
  214. - --no-align
  215. - --command=SELECT tablename FROM pg_tables WHERE schemaname = 'public' ORDER BY tablename
  216. register: matrix_bot_honoroit_tables
  217. changed_when: false
  218. - name: Assert Honoroit migrated a substantial schema into the configured Postgres database
  219. ansible.builtin.assert:
  220. that:
  221. - matrix_bot_honoroit_tables.rc == 0
  222. - "'crypto_account' in matrix_bot_honoroit_table_names"
  223. - "'crypto_device' in matrix_bot_honoroit_table_names"
  224. - "'crypto_megolm_inbound_session' in matrix_bot_honoroit_table_names"
  225. - "'crypto_olm_session' in matrix_bot_honoroit_table_names"
  226. - "'crypto_secrets' in matrix_bot_honoroit_table_names"
  227. - "'crypto_version' in matrix_bot_honoroit_table_names"
  228. - "'mx_registrations' in matrix_bot_honoroit_table_names"
  229. - "'mx_room_state' in matrix_bot_honoroit_table_names"
  230. - "'mx_user_profile' in matrix_bot_honoroit_table_names"
  231. - "'mx_version' in matrix_bot_honoroit_table_names"
  232. - matrix_bot_honoroit_table_names | length == 17
  233. fail_msg: >-
  234. Honoroit did not create its crypto schema in {{ matrix_bot_honoroit_database_name }}
  235. (found {{ matrix_bot_honoroit_table_names | length }} table(s):
  236. {{ matrix_bot_honoroit_table_names | join(', ') }})
  237. success_msg: "Honoroit migrated its crypto schema into the configured Postgres database"
  238. vars:
  239. matrix_bot_honoroit_table_names: "{{ matrix_bot_honoroit_tables.stdout_lines | select | list }}"
  240. - name: Read Honoroit's database migration markers
  241. ansible.builtin.command:
  242. argv:
  243. - docker
  244. - exec
  245. - matrix-postgres-molecule
  246. - psql
  247. - --username={{ matrix_bot_honoroit_database_username }}
  248. - --dbname={{ matrix_bot_honoroit_database_name }}
  249. - --tuples-only
  250. - --no-align
  251. - "--command=SELECT 'crypto:' || version || ':' || compat FROM crypto_version UNION ALL SELECT 'state:' || version || ':' || compat FROM mx_version ORDER BY 1"
  252. register: matrix_bot_honoroit_migration_versions
  253. changed_when: false
  254. - name: Assert Honoroit's Postgres migrations reached the pinned schema versions
  255. ansible.builtin.assert:
  256. that:
  257. - matrix_bot_honoroit_migration_versions.rc == 0
  258. - matrix_bot_honoroit_migration_versions.stdout_lines == ['crypto:19:15', 'state:10:3']
  259. fail_msg: >-
  260. Honoroit's database migration markers are missing or unexpected
  261. ({{ matrix_bot_honoroit_migration_versions.stdout | default('no output') | trim }})
  262. success_msg: "Honoroit's Postgres migrations reached the pinned schema versions"
  263. - name: Read Honoroit's full systemd journal
  264. ansible.builtin.command:
  265. argv:
  266. - journalctl
  267. - --unit=matrix-bot-honoroit.service
  268. - --no-pager
  269. register: matrix_bot_honoroit_journal
  270. changed_when: false
  271. - name: Assert the journal records successful initialization and configured debug logging
  272. ansible.builtin.assert:
  273. that:
  274. - "'Honoroit' in matrix_bot_honoroit_journal_plain"
  275. - "'starting bot...' in matrix_bot_honoroit_journal_plain"
  276. - "'client has been started' in matrix_bot_honoroit_journal_plain"
  277. - "'cannot initialize the bot' not in matrix_bot_honoroit_journal_plain"
  278. - "'matrix bot crashed' not in matrix_bot_honoroit_journal_plain"
  279. fail_msg: "Honoroit's journal does not show a clean debug-level startup"
  280. success_msg: "Honoroit's journal records a clean debug-level startup"
  281. vars:
  282. matrix_bot_honoroit_journal_plain: >-
  283. {{ matrix_bot_honoroit_journal.stdout
  284. | regex_replace('\x1B\[[0-?]*[ -/]*[@-~]', '') }}
  285. - name: Inspect the running Honoroit container
  286. ansible.builtin.command:
  287. argv:
  288. - docker
  289. - container
  290. - inspect
  291. - matrix-bot-honoroit
  292. register: matrix_bot_honoroit_container_inspect
  293. changed_when: false
  294. - name: Assert the running container uses the exact image pinned by the role
  295. ansible.builtin.assert:
  296. that:
  297. - matrix_bot_honoroit_runtime.Config.Image == matrix_bot_honoroit_expected_image
  298. fail_msg: >-
  299. The running image is {{ matrix_bot_honoroit_runtime.Config.Image }}, expected
  300. {{ matrix_bot_honoroit_expected_image }} from defaults/main.yml
  301. success_msg: "The running container uses the exact image pinned by the role"
  302. vars:
  303. matrix_bot_honoroit_expected_image: >-
  304. {{ matrix_bot_honoroit_role_defaults.matrix_bot_honoroit_container_image_registry_prefix_upstream_default }}etkecc/honoroit:{{ matrix_bot_honoroit_role_defaults.matrix_bot_honoroit_version }}
  305. - name: Assert the running container preserves the image and systemd lifecycle contract
  306. ansible.builtin.assert:
  307. that:
  308. - matrix_bot_honoroit_runtime.Config.Entrypoint == ['/bin/honoroit']
  309. - matrix_bot_honoroit_runtime.Config.Cmd is none
  310. - matrix_bot_honoroit_runtime.Config.WorkingDir == '/'
  311. - matrix_bot_honoroit_runtime.HostConfig.RestartPolicy.Name == 'no'
  312. - matrix_bot_honoroit_runtime.HostConfig.AutoRemove is sameas true
  313. - matrix_bot_honoroit_runtime.HostConfig.LogConfig.Type == 'none'
  314. fail_msg: "The running container has an unexpected command or Docker lifecycle contract"
  315. success_msg: "The running container preserves the image command and systemd lifecycle contract"
  316. - name: Assert the running container uses the configured identity and hardening
  317. ansible.builtin.assert:
  318. that:
  319. - matrix_bot_honoroit_runtime.Config.User == '1234:1234'
  320. - matrix_bot_honoroit_runtime.HostConfig.ReadonlyRootfs is sameas true
  321. - matrix_bot_honoroit_runtime.HostConfig.CapDrop == ['ALL']
  322. - matrix_bot_honoroit_runtime.HostConfig.PidsLimit == 73
  323. - matrix_bot_honoroit_runtime.HostConfig.Tmpfs['/tmp'] == 'rw,noexec,nosuid,size=16m'
  324. fail_msg: "The running container lost its configured identity or hardening"
  325. success_msg: "The running container uses the configured identity and hardening"
  326. - name: Assert the running container has only private network attachments
  327. ansible.builtin.assert:
  328. that:
  329. - matrix_bot_honoroit_runtime.HostConfig.NetworkMode == matrix_bot_honoroit_container_network
  330. - matrix_bot_honoroit_runtime.NetworkSettings.Networks.keys() | sort == ([matrix_bot_honoroit_container_network] + matrix_bot_honoroit_container_additional_networks) | sort
  331. - matrix_bot_honoroit_runtime.HostConfig.PortBindings | length == 0
  332. fail_msg: "The running container lost a private network or published a host port"
  333. success_msg: "The running container has both private networks and no published host ports"
  334. - name: Assert the writable data mount is scoped to Honoroit's data directory
  335. ansible.builtin.assert:
  336. that:
  337. - matrix_bot_honoroit_runtime.Mounts | length == 1
  338. - matrix_bot_honoroit_data_mounts | length == 1
  339. - matrix_bot_honoroit_data_mounts[0].Source == matrix_bot_honoroit_data_path
  340. - matrix_bot_honoroit_data_mounts[0].RW is sameas true
  341. fail_msg: "The running container's /data mount does not match the role-managed data path"
  342. success_msg: "The running container has the role-managed writable /data mount"
  343. - name: Assert the running process received the role-rendered environment
  344. ansible.builtin.assert:
  345. that:
  346. - matrix_bot_honoroit_runtime_env.HONOROIT_DB_DSN == matrix_bot_honoroit_rendered_env.HONOROIT_DB_DSN
  347. - matrix_bot_honoroit_runtime_env.HONOROIT_HOMESERVER == matrix_bot_honoroit_rendered_env.HONOROIT_HOMESERVER
  348. - matrix_bot_honoroit_runtime_env.HONOROIT_AUTH_METRICS_LOGIN == matrix_bot_honoroit_rendered_env.HONOROIT_AUTH_METRICS_LOGIN
  349. - matrix_bot_honoroit_runtime_env.HONOROIT_PORT == ':' ~ (matrix_bot_honoroit_container_port | string)
  350. - matrix_bot_honoroit_runtime_env.MOLECULE_HONOROIT_MARKER == 'role-rendered-environment'
  351. fail_msg: "The live container environment differs from the file the role rendered"
  352. success_msg: "The live container received the role-rendered environment"
  353. - name: Read the labels file the role rendered
  354. ansible.builtin.slurp:
  355. src: "{{ matrix_bot_honoroit_config_path }}/labels"
  356. register: matrix_bot_honoroit_labels_file
  357. - name: Assert the parsed labels contain the configured metrics router
  358. ansible.builtin.assert:
  359. that:
  360. - matrix_bot_honoroit_rendered_labels['traefik.enable'] == 'true'
  361. - matrix_bot_honoroit_rendered_labels['traefik.docker.network'] == matrix_bot_honoroit_container_network
  362. - matrix_bot_honoroit_rendered_labels['traefik.http.services.matrix-bot-honoroit-metrics.loadbalancer.server.port'] == (matrix_bot_honoroit_container_port | string)
  363. - matrix_bot_honoroit_rendered_labels['traefik.http.routers.matrix-bot-honoroit-metrics.rule'] == 'Host(`honoroit.molecule.local`) && Path(`/molecule-honoroit/molecule-metrics`)'
  364. - matrix_bot_honoroit_rendered_labels['traefik.http.routers.matrix-bot-honoroit-metrics.priority'] == '710'
  365. - matrix_bot_honoroit_rendered_labels['traefik.http.routers.matrix-bot-honoroit-metrics.service'] == 'matrix-bot-honoroit-metrics'
  366. - matrix_bot_honoroit_rendered_labels['traefik.http.routers.matrix-bot-honoroit-metrics.entrypoints'] == 'molecule-web'
  367. - matrix_bot_honoroit_rendered_labels['traefik.http.routers.matrix-bot-honoroit-metrics.tls'] == 'false'
  368. - matrix_bot_honoroit_rendered_labels['traefik.http.routers.matrix-bot-honoroit-metrics.tls.certResolver'] is not defined
  369. fail_msg: "The parsed labels lost the scenario's metrics router contract"
  370. success_msg: "The parsed labels contain the configured metrics router"
  371. - name: Assert the parsed labels contain the configured middleware chain
  372. ansible.builtin.assert:
  373. that:
  374. - matrix_bot_honoroit_rendered_labels['traefik.http.middlewares.matrix-bot-honoroit-slashless-redirect.redirectregex.regex'] == '(/molecule-honoroit)$'
  375. - matrix_bot_honoroit_rendered_labels['traefik.http.middlewares.matrix-bot-honoroit-slashless-redirect.redirectregex.replacement'] == '${1}/'
  376. - matrix_bot_honoroit_rendered_labels['traefik.http.middlewares.matrix-bot-honoroit-strip-prefix.stripprefix.prefixes'] == '/molecule-honoroit'
  377. - matrix_bot_honoroit_rendered_labels['traefik.http.middlewares.matrix-bot-honoroit-add-headers.headers.customresponseheaders.X-Molecule-Honoroit'] == 'scenario'
  378. - matrix_bot_honoroit_rendered_labels['traefik.http.middlewares.matrix-bot-honoroit-add-headers.headers.customresponseheaders.X-Robots-Tag'] == 'noindex'
  379. - matrix_bot_honoroit_rendered_labels['traefik.http.routers.matrix-bot-honoroit-metrics.middlewares'] == 'matrix-bot-honoroit-slashless-redirect,matrix-bot-honoroit-strip-prefix,matrix-bot-honoroit-add-headers'
  380. fail_msg: "The parsed labels lost the scenario's path and response-header middlewares"
  381. success_msg: "The parsed labels contain the configured middleware chain"
  382. - name: Assert the live container received the rendered router and middleware labels
  383. ansible.builtin.assert:
  384. that:
  385. - matrix_bot_honoroit_runtime.Config.Labels['traefik.http.services.matrix-bot-honoroit-metrics.loadbalancer.server.port'] == (matrix_bot_honoroit_container_port | string)
  386. - matrix_bot_honoroit_runtime.Config.Labels['traefik.http.routers.matrix-bot-honoroit-metrics.rule'] == matrix_bot_honoroit_rendered_labels['traefik.http.routers.matrix-bot-honoroit-metrics.rule']
  387. - matrix_bot_honoroit_runtime.Config.Labels['traefik.http.routers.matrix-bot-honoroit-metrics.priority'] == matrix_bot_honoroit_rendered_labels['traefik.http.routers.matrix-bot-honoroit-metrics.priority']
  388. - matrix_bot_honoroit_runtime.Config.Labels['traefik.http.routers.matrix-bot-honoroit-metrics.middlewares'] == matrix_bot_honoroit_rendered_labels['traefik.http.routers.matrix-bot-honoroit-metrics.middlewares']
  389. - matrix_bot_honoroit_runtime.Config.Labels['traefik.http.middlewares.matrix-bot-honoroit-add-headers.headers.customresponseheaders.X-Molecule-Honoroit'] == 'scenario'
  390. - matrix_bot_honoroit_runtime.Config.Labels['molecule.honoroit.scenario'] == 'live-postgres-and-metrics'
  391. fail_msg: "The live container labels differ from the rendered routing contract"
  392. success_msg: "The live container received the rendered router and middleware labels"
  393. - name: Inspect role-rendered support file ownership and permissions
  394. ansible.builtin.stat:
  395. path: "{{ item }}"
  396. loop:
  397. - "{{ matrix_bot_honoroit_config_path }}/env"
  398. - "{{ matrix_bot_honoroit_config_path }}/labels"
  399. register: matrix_bot_honoroit_support_files
  400. - name: Assert support files are owned by Matrix and not world-readable
  401. ansible.builtin.assert:
  402. that:
  403. - matrix_bot_honoroit_support_files.results | map(attribute='stat.uid') | unique | list == [1234]
  404. - matrix_bot_honoroit_support_files.results | map(attribute='stat.gid') | unique | list == [1234]
  405. - matrix_bot_honoroit_support_files.results | map(attribute='stat.mode') | unique | list == ['0640']
  406. fail_msg: "Honoroit's support files have unexpected ownership or permissions"
  407. success_msg: "Honoroit's support files are Matrix-owned and mode 0640"