Matrix Docker Ansible eploy
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

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