Matrix Docker Ansible eploy
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

177 行
8.2 KiB

  1. # SPDX-FileCopyrightText: 2026 Slavi Pantaleev
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - name: Verify matrix-alertmanager-receiver
  6. hosts: all
  7. become: true
  8. vars_files:
  9. - "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/vars.yml"
  10. gather_facts: false
  11. tasks:
  12. # The version is read out of the role's own defaults rather than pinned in
  13. # molecule.yml, so that the assertion further down compares the running
  14. # image against what defaults/main.yml actually ships. Pinning it here
  15. # would make that assertion compare the scenario with itself.
  16. - name: Load the role's defaults under a separate name
  17. ansible.builtin.include_vars:
  18. file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/main.yml"
  19. name: matrix_alertmanager_receiver_role_defaults
  20. - name: Wait for the matrix-alertmanager-receiver service to become active
  21. ansible.builtin.systemd_service:
  22. name: matrix-alertmanager-receiver.service
  23. register: matrix_alertmanager_receiver_service
  24. until: matrix_alertmanager_receiver_service.status.ActiveState == 'active'
  25. retries: 30
  26. delay: 5
  27. failed_when: false
  28. # `Restart=always` means a crash-looping container still reports `active`,
  29. # so the restart counter is checked alongside it. Asserted as `is defined`
  30. # too, because `| int` turns a missing property into 0 and would pass
  31. # vacuously on a systemd that does not expose it.
  32. - name: Assert the service is active and has not been restarting
  33. ansible.builtin.assert:
  34. that:
  35. - matrix_alertmanager_receiver_service.status.ActiveState == 'active'
  36. - matrix_alertmanager_receiver_service.status.NRestarts is defined
  37. - matrix_alertmanager_receiver_service.status.NRestarts | int == 0
  38. fail_msg: >-
  39. matrix-alertmanager-receiver.service is
  40. {{ matrix_alertmanager_receiver_service.status.ActiveState | default('unknown') }}
  41. after {{ matrix_alertmanager_receiver_service.status.NRestarts | default('?') }}
  42. automatic restart(s)
  43. success_msg: "matrix-alertmanager-receiver.service is active and has not restarted"
  44. # Probed from inside the container network rather than from the host: the
  45. # role publishes no host port, exactly as it does in a real deployment,
  46. # where Traefik reaches it over the network instead.
  47. - name: Wait for matrix-alertmanager-receiver to answer on the port the role configured
  48. ansible.builtin.command:
  49. argv:
  50. - docker
  51. - run
  52. - --rm
  53. - --network={{ matrix_alertmanager_receiver_container_network }}
  54. - "{{ molecule_shared_image_curl }}"
  55. - --silent
  56. - --show-error
  57. - --write-out
  58. - "\nHTTP_STATUS=%{http_code}"
  59. - "http://matrix-alertmanager-receiver:{{ matrix_alertmanager_receiver_config_http_port }}{{ matrix_alertmanager_receiver_config_http_metrics_path }}"
  60. register: matrix_alertmanager_receiver_metrics
  61. changed_when: false
  62. until: "'HTTP_STATUS=200' in matrix_alertmanager_receiver_metrics.stdout"
  63. retries: 24
  64. delay: 5
  65. failed_when: false
  66. # The port and the metrics path are both non-default in this scenario, so a
  67. # 200 here is only reachable if the configuration the role rendered is what
  68. # the process is actually running on.
  69. - name: Assert the configured port and metrics path reached the process
  70. ansible.builtin.assert:
  71. that:
  72. - "'HTTP_STATUS=200' in matrix_alertmanager_receiver_metrics.stdout"
  73. fail_msg: >-
  74. matrix-alertmanager-receiver did not serve metrics on port
  75. {{ matrix_alertmanager_receiver_config_http_port }} at
  76. {{ matrix_alertmanager_receiver_config_http_metrics_path }}
  77. ({{ matrix_alertmanager_receiver_metrics.stdout | default('no output') }})
  78. success_msg: >-
  79. matrix-alertmanager-receiver serves metrics on the configured port and path
  80. - name: Assert the metrics endpoint is really Prometheus metrics
  81. ansible.builtin.assert:
  82. that:
  83. - "'# HELP' in matrix_alertmanager_receiver_metrics.stdout"
  84. fail_msg: >-
  85. The metrics endpoint answered, but did not return Prometheus metrics
  86. success_msg: "The metrics endpoint returns Prometheus metrics"
  87. # A negative control for the assertion above: the role's own default metrics
  88. # path must NOT answer, or a 200 on the configured path would prove nothing
  89. # about the configuration having been applied.
  90. - name: Ask for the role's default metrics path, which this scenario moved away from
  91. ansible.builtin.command:
  92. argv:
  93. - docker
  94. - run
  95. - --rm
  96. - --network={{ matrix_alertmanager_receiver_container_network }}
  97. - "{{ molecule_shared_image_curl }}"
  98. - --silent
  99. - --output
  100. - /dev/null
  101. - --write-out
  102. - "HTTP_STATUS=%{http_code}"
  103. - "http://matrix-alertmanager-receiver:{{ matrix_alertmanager_receiver_config_http_port }}/metrics"
  104. register: matrix_alertmanager_receiver_default_path
  105. changed_when: false
  106. failed_when: false
  107. - name: Assert the default metrics path does not answer
  108. ansible.builtin.assert:
  109. that:
  110. - "'HTTP_STATUS=200' not in matrix_alertmanager_receiver_default_path.stdout"
  111. fail_msg: >-
  112. /metrics answered as well, so serving on
  113. {{ matrix_alertmanager_receiver_config_http_metrics_path }} does not
  114. prove the role's configuration reached the process
  115. ({{ matrix_alertmanager_receiver_default_path.stdout | default('no output') }})
  116. success_msg: "Only the configured metrics path answers"
  117. - name: Read the configuration file the role rendered
  118. ansible.builtin.slurp:
  119. src: "{{ matrix_alertmanager_receiver_config_path }}/config.yml"
  120. register: matrix_alertmanager_receiver_config_file
  121. - name: Assert the rendered configuration carries this scenario's values
  122. ansible.builtin.assert:
  123. that:
  124. - matrix_alertmanager_receiver_config_matrix_user_id in matrix_alertmanager_receiver_config_rendered
  125. - matrix_alertmanager_receiver_config_matrix_access_token in matrix_alertmanager_receiver_config_rendered
  126. - "'molecule-room' in matrix_alertmanager_receiver_config_rendered"
  127. fail_msg: "The rendered configuration does not carry the scenario's Matrix settings"
  128. success_msg: "The rendered configuration carries the scenario's Matrix settings"
  129. vars:
  130. matrix_alertmanager_receiver_config_rendered: "{{ matrix_alertmanager_receiver_config_file.content | b64decode }}"
  131. - name: Assert the running container is the image the role pins
  132. ansible.builtin.command:
  133. argv:
  134. - docker
  135. - container
  136. - inspect
  137. - matrix-alertmanager-receiver
  138. - --format
  139. - "{{ '{{' }} .Config.Image {{ '}}' }}"
  140. register: matrix_alertmanager_receiver_image
  141. changed_when: false
  142. - name: Assert the image carries the version defaults/main.yml pins
  143. ansible.builtin.assert:
  144. that:
  145. - matrix_alertmanager_receiver_role_defaults.matrix_alertmanager_receiver_version in matrix_alertmanager_receiver_image.stdout
  146. fail_msg: >-
  147. The running container is {{ matrix_alertmanager_receiver_image.stdout }},
  148. which does not carry the pinned version {{ matrix_alertmanager_receiver_role_defaults.matrix_alertmanager_receiver_version }}
  149. success_msg: "The running container is the version defaults/main.yml pins"
  150. - name: Read the labels the role rendered
  151. ansible.builtin.slurp:
  152. src: "{{ matrix_alertmanager_receiver_base_path }}/labels"
  153. register: matrix_alertmanager_receiver_labels
  154. - name: Assert no Traefik labels are emitted while Traefik support is disabled
  155. ansible.builtin.assert:
  156. that:
  157. - "'traefik.' not in (matrix_alertmanager_receiver_labels.content | b64decode)"
  158. fail_msg: >-
  159. Traefik labels were emitted even though
  160. matrix_alertmanager_receiver_container_labels_traefik_enabled is false
  161. success_msg: "No Traefik labels are emitted while Traefik support is disabled"