Matrix Docker Ansible eploy
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

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