mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2026-10-20 21:34:15 +00:00
Containers are created with `--rm`, so Docker removes them asynchronously after they stop. The pre-start `docker rm` returns immediately while that removal is still in progress (its error is suppressed), and the following `docker create --name` can fail with "The container name ... is already in use". This is easy to hit since systemd_service_manager switched its default restart mode to `all-at-once`: many containers stop and start at the same time and Docker falls behind on removals. The playbook then fails at "Restart systemd services needing restart at once", even though the services recover on their own (`Restart=always`) a little later. The external roles (MASH, devture) were hardened against this in 2026-03 (see mother-of-all-self-hosting/ansible-role-valkey@0ba79c0), but the roles in `roles/custom` never were. This ports the same bounded cleanup loop to them: stop, force-remove, and wait until Docker releases the name, failing explicitly after a timeout. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
275 lines
16 KiB
YAML
275 lines
16 KiB
YAML
# SPDX-FileCopyrightText: 2024 - 2025 Slavi Pantaleev
|
|
# SPDX-FileCopyrightText: 2024 - 2025 Suguru Hirahara
|
|
#
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
---
|
|
|
|
# matrix-alertmanager-receiver is a service which receives webhook payloads from Prometheus' Alertmanager and forwards them to a Matrix room.
|
|
# Project source code URL: https://github.com/metio/matrix-alertmanager-receiver
|
|
|
|
matrix_alertmanager_receiver_enabled: true
|
|
|
|
# renovate: datasource=docker depName=docker.io/metio/matrix-alertmanager-receiver
|
|
matrix_alertmanager_receiver_version: 2026.9.23
|
|
|
|
matrix_alertmanager_receiver_scheme: https
|
|
|
|
# The hostname at which matrix-alertmanager-receiver is served.
|
|
matrix_alertmanager_receiver_hostname: ''
|
|
|
|
# The path at which matrix-alertmanager-receiver is served.
|
|
# This value must either be `/` or not end with a slash (e.g. `/matrix-alertmanager-receiver`).
|
|
matrix_alertmanager_receiver_path_prefix: /
|
|
|
|
matrix_alertmanager_receiver_base_path: "{{ matrix_base_data_path }}/alertmanager-receiver"
|
|
matrix_alertmanager_receiver_config_path: "{{ matrix_alertmanager_receiver_base_path }}/config"
|
|
|
|
matrix_alertmanager_receiver_container_image_self_build: false
|
|
matrix_alertmanager_receiver_container_image_self_build_repo: https://github.com/metio/matrix-alertmanager-receiver
|
|
matrix_alertmanager_receiver_container_image_self_build_repo_version: "{{ 'main' if matrix_alertmanager_receiver_version == 'main' else matrix_alertmanager_receiver_version }}"
|
|
matrix_alertmanager_receiver_container_src_path: "{{ matrix_alertmanager_receiver_base_path }}/container-src"
|
|
|
|
matrix_alertmanager_receiver_container_image: "{{ matrix_alertmanager_receiver_container_image_registry_prefix }}metio/matrix-alertmanager-receiver:{{ matrix_alertmanager_receiver_container_image_tag }}"
|
|
matrix_alertmanager_receiver_container_image_tag: "{{ matrix_alertmanager_receiver_version }}"
|
|
matrix_alertmanager_receiver_container_image_registry_prefix: "{{ matrix_alertmanager_receiver_container_image_registry_prefix_upstream }}"
|
|
matrix_alertmanager_receiver_container_image_registry_prefix_upstream: "{{ matrix_alertmanager_receiver_container_image_registry_prefix_upstream_default }}"
|
|
matrix_alertmanager_receiver_container_image_registry_prefix_upstream_default: "docker.io/"
|
|
|
|
# The base container network. It will be auto-created by this role if it doesn't exist already.
|
|
matrix_alertmanager_receiver_container_network: ''
|
|
|
|
# A list of additional container networks that the container would be connected to.
|
|
# The role does not create these networks, so make sure they already exist.
|
|
matrix_alertmanager_receiver_container_additional_networks: "{{ matrix_alertmanager_receiver_container_additional_networks_default + matrix_alertmanager_receiver_container_additional_networks_auto + matrix_alertmanager_receiver_container_additional_networks_custom }}"
|
|
matrix_alertmanager_receiver_container_additional_networks_default: []
|
|
matrix_alertmanager_receiver_container_additional_networks_auto: []
|
|
matrix_alertmanager_receiver_container_additional_networks_custom: []
|
|
|
|
# Controls whether matrix-alertmanager-receiver metrics should be proxied (exposed) on `matrix.example.com/metrics/matrix-alertmanager-receiver`
|
|
matrix_alertmanager_receiver_metrics_proxying_enabled: false
|
|
matrix_alertmanager_receiver_metrics_proxying_hostname: ''
|
|
matrix_alertmanager_receiver_metrics_proxying_path: /metrics/matrix-alertmanager-receiver
|
|
|
|
# matrix_alertmanager_receiver_container_labels_traefik_enabled controls whether labels to assist a Traefik reverse-proxy will be attached to the container.
|
|
# See `../templates/labels.j2` for details.
|
|
#
|
|
# To inject your own other container labels, see `matrix_alertmanager_receiver_container_labels_additional_labels`.
|
|
matrix_alertmanager_receiver_container_labels_traefik_enabled: true
|
|
matrix_alertmanager_receiver_container_labels_traefik_docker_network: "{{ matrix_alertmanager_receiver_container_network }}"
|
|
matrix_alertmanager_receiver_container_labels_traefik_hostname: "{{ matrix_alertmanager_receiver_hostname }}"
|
|
# The path prefix must either be `/` or not end with a slash (e.g. `/matrix-alertmanager-receiver`).
|
|
matrix_alertmanager_receiver_container_labels_traefik_path_prefix: "{{ matrix_alertmanager_receiver_path_prefix }}"
|
|
matrix_alertmanager_receiver_container_labels_traefik_rule: "Host(`{{ matrix_alertmanager_receiver_container_labels_traefik_hostname }}`){% if matrix_alertmanager_receiver_container_labels_traefik_path_prefix != '/' %} && PathPrefix(`{{ matrix_alertmanager_receiver_container_labels_traefik_path_prefix }}`){% endif %}"
|
|
matrix_alertmanager_receiver_container_labels_traefik_priority: 0
|
|
matrix_alertmanager_receiver_container_labels_traefik_entrypoints: web-secure
|
|
matrix_alertmanager_receiver_container_labels_traefik_tls: "{{ matrix_alertmanager_receiver_container_labels_traefik_entrypoints != 'web' }}"
|
|
matrix_alertmanager_receiver_container_labels_traefik_tls_certResolver: default # noqa var-naming
|
|
|
|
# Controls whether labels will be added that expose metrics (see `matrix_alertmanager_receiver_metrics_proxying_enabled`) for matrix-alertmanager-receiver
|
|
matrix_alertmanager_receiver_container_labels_public_metrics_enabled: "{{ matrix_alertmanager_receiver_metrics_enabled and matrix_alertmanager_receiver_metrics_proxying_enabled }}"
|
|
matrix_alertmanager_receiver_container_labels_public_metrics_traefik_path: "{{ matrix_alertmanager_receiver_metrics_proxying_path }}"
|
|
matrix_alertmanager_receiver_container_labels_public_metrics_traefik_rule: "Host(`{{ matrix_alertmanager_receiver_metrics_proxying_hostname }}`) && Path(`{{ matrix_alertmanager_receiver_container_labels_public_metrics_traefik_path }}`)"
|
|
matrix_alertmanager_receiver_container_labels_public_metrics_traefik_priority: 0
|
|
matrix_alertmanager_receiver_container_labels_public_metrics_traefik_entrypoints: "{{ matrix_alertmanager_receiver_container_labels_traefik_entrypoints }}"
|
|
matrix_alertmanager_receiver_container_labels_public_metrics_traefik_tls: "{{ matrix_alertmanager_receiver_container_labels_public_metrics_traefik_entrypoints != 'web' }}"
|
|
matrix_alertmanager_receiver_container_labels_public_metrics_traefik_tls_certResolver: "{{ matrix_alertmanager_receiver_container_labels_traefik_tls_certResolver }}" # noqa var-naming
|
|
matrix_alertmanager_receiver_container_labels_public_metrics_middleware_basic_auth_enabled: false
|
|
# See: https://doc.traefik.io/traefik/middlewares/http/basicauth/#users
|
|
matrix_alertmanager_receiver_container_labels_public_metrics_middleware_basic_auth_users: ''
|
|
|
|
# matrix_alertmanager_receiver_container_labels_additional_labels contains a multiline string with additional labels to add to the container label file.
|
|
# See `../templates/labels.j2` for details.
|
|
#
|
|
# Example:
|
|
# matrix_alertmanager_receiver_container_labels_additional_labels: |
|
|
# my.label=1
|
|
# another.label="here"
|
|
matrix_alertmanager_receiver_container_labels_additional_labels: ''
|
|
|
|
# A list of extra arguments to pass to the container
|
|
matrix_alertmanager_receiver_container_extra_arguments: []
|
|
|
|
# Controls how long the pre-start cleanup should wait for stale container-name release
|
|
# before failing startup explicitly.
|
|
matrix_alertmanager_receiver_container_cleanup_timeout_seconds: "{{ devture_systemd_docker_base_container_cleanup_timeout_seconds }}"
|
|
|
|
# Controls the delay between pre-start cleanup retries.
|
|
matrix_alertmanager_receiver_container_cleanup_retry_delay_seconds: "{{ devture_systemd_docker_base_container_cleanup_retry_delay_seconds }}"
|
|
|
|
# Shell command used in the systemd pre-start phase to deterministically remove a stale
|
|
# container and wait until Docker releases its name.
|
|
matrix_alertmanager_receiver_container_cleanup_command: |
|
|
i=0;
|
|
while [ "$i" -lt {{ matrix_alertmanager_receiver_container_cleanup_timeout_seconds }} ]; do
|
|
{{ devture_systemd_docker_base_host_command_docker }} stop -t {{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-alertmanager-receiver >/dev/null 2>&1 || true;
|
|
{{ devture_systemd_docker_base_host_command_docker }} rm -f matrix-alertmanager-receiver >/dev/null 2>&1 || true;
|
|
if {{ devture_systemd_docker_base_host_command_docker }} container inspect matrix-alertmanager-receiver >/dev/null 2>&1; then
|
|
i=$((i + 1));
|
|
sleep {{ matrix_alertmanager_receiver_container_cleanup_retry_delay_seconds }};
|
|
continue;
|
|
fi;
|
|
if {{ devture_systemd_docker_base_host_command_docker }} info >/dev/null 2>&1; then
|
|
exit 0;
|
|
fi;
|
|
echo "Failed to query Docker daemon while cleaning up matrix-alertmanager-receiver" >&2;
|
|
exit 1;
|
|
done;
|
|
echo "Failed to remove stale container matrix-alertmanager-receiver after {{ matrix_alertmanager_receiver_container_cleanup_timeout_seconds }} attempts" >&2;
|
|
exit 1
|
|
|
|
# Controls the `--log-level` argument passed to the container process.
|
|
# Valid values: error, warn, info, debug
|
|
matrix_alertmanager_receiver_container_process_argument_log_level: info
|
|
|
|
# A list of extra arguments to pass to the container process.
|
|
matrix_alertmanager_receiver_container_process_extra_arguments: []
|
|
|
|
# List of systemd services that matrix-alertmanager-receiver-proxy.service depends on
|
|
matrix_alertmanager_receiver_systemd_required_services_list: "{{ matrix_alertmanager_receiver_systemd_required_services_list_default + matrix_alertmanager_receiver_systemd_required_services_list_auto + matrix_alertmanager_receiver_systemd_required_services_list_custom }}"
|
|
matrix_alertmanager_receiver_systemd_required_services_list_default: "{{ [devture_systemd_docker_base_docker_service_name] if devture_systemd_docker_base_docker_service_name else [] }}"
|
|
matrix_alertmanager_receiver_systemd_required_services_list_auto: []
|
|
matrix_alertmanager_receiver_systemd_required_services_list_custom: []
|
|
|
|
# List of systemd services that matrix-alertmanager-receiver-proxy.service wants
|
|
matrix_alertmanager_receiver_systemd_wanted_services_list: []
|
|
|
|
# Controls the `http.port` configuration setting.
|
|
matrix_alertmanager_receiver_config_http_port: 12345
|
|
|
|
# Controls the `http.alerts-path-prefix` configuration setting.
|
|
matrix_alertmanager_receiver_config_http_alerts_path_prefix: /alerts
|
|
|
|
# Controls the `http.metrics-enabled` configuration setting.
|
|
matrix_alertmanager_receiver_config_http_metrics_enabled: false
|
|
|
|
# Controls the `http.metrics-path` configuration setting.
|
|
matrix_alertmanager_receiver_config_http_metrics_path: /metrics
|
|
|
|
# Controls the `matrix.homeserver-url` configuration setting.
|
|
matrix_alertmanager_receiver_config_matrix_homeserver_url: ''
|
|
|
|
# Controls the `matrix.user-id` configuration setting.
|
|
matrix_alertmanager_receiver_config_matrix_user_id: "@{{ matrix_alertmanager_receiver_config_matrix_user_id_localpart }}:{{ matrix_domain }}"
|
|
matrix_alertmanager_receiver_config_matrix_user_id_localpart: "bot.alertmanager.receiver"
|
|
|
|
# Controls the `matrix.access-token` configuration setting.
|
|
matrix_alertmanager_receiver_config_matrix_access_token: ''
|
|
|
|
# Controls the `matrix.room-mapping` configuration setting.
|
|
#
|
|
# Example:
|
|
# matrix_alertmanager_receiver_config_matrix_room:
|
|
# simple-name: "!qporfwt:example.com"
|
|
# another-name: "!aaabaa:example.com"
|
|
matrix_alertmanager_receiver_config_matrix_room_mapping: {}
|
|
|
|
# Controls the `templating.external-url-mapping` configuration setting.
|
|
#
|
|
# The key is the original value taken from the Alertmanager payload
|
|
# The value is the mapped value which will be available as '.ExternalURL' in templates
|
|
#
|
|
# Example:
|
|
# matrix_alertmanager_receiver_config_templating_external_url_mapping:
|
|
# "http://alertmanager:9093": https://alertmanager.example.com
|
|
# "http://alertmanager:9094": https://another.alertmanager.example.com
|
|
matrix_alertmanager_receiver_config_templating_external_url_mapping: {}
|
|
|
|
# Controls the `templating.generator-url-mapping` configuration setting.
|
|
#
|
|
# The key is the original value taken from the Alertmanager payload
|
|
# The value is the mapped value which will be available as '.ExternalURL' in templates
|
|
#
|
|
# Example:
|
|
# matrix_alertmanager_receiver_config_templating_generator_url_mapping:
|
|
# "http://prometheus:8080": https://prometheus.example.com
|
|
# "http://prometheus:8081": https://another.prometheus.example.com
|
|
matrix_alertmanager_receiver_config_templating_generator_url_mapping: {}
|
|
|
|
# Controls the `templating.firing-template` configuration setting.
|
|
matrix_alertmanager_receiver_config_templating_firing_template: |-
|
|
{% raw %}
|
|
{{ $color := "yellow" }}
|
|
{{ if eq .Alert.Labels.severity "warning" }}
|
|
{{ $color = "orange" }}
|
|
{{ else if eq .Alert.Labels.severity "critical" }}
|
|
{{ $color = "red" }}
|
|
{{ end }}
|
|
{{ if eq .Alert.Status "resolved" }}
|
|
{{ $color = "green" }}
|
|
{{ end }}
|
|
<p>
|
|
<strong><font color="{{ $color }}">{{ .Alert.Status | ToUpper }}</font></strong>
|
|
{{ if .Alert.Labels.name }}
|
|
{{ .Alert.Labels.name }}
|
|
{{ else if .Alert.Labels.alertname }}
|
|
{{ .Alert.Labels.alertname }}
|
|
{{ end }}
|
|
>>
|
|
{{ if .Alert.Labels.severity }}
|
|
{{ .Alert.Labels.severity | ToUpper }}:
|
|
{{ end }}
|
|
{{ if .Alert.Annotations.description }}
|
|
{{ .Alert.Annotations.description }}
|
|
{{ else if .Alert.Annotations.summary }}
|
|
{{ .Alert.Annotations.summary }}
|
|
{{ end }}
|
|
>>
|
|
{{ if .Alert.Annotations.runbook_url }}
|
|
<a href="{{ .Alert.Annotations.runbook_url }}">Runbook</a> |
|
|
{{ end }}
|
|
{{ if .Alert.Annotations.dashboard }}
|
|
<a href="{{ .Alert.Annotations.dashboard }}">Dashboard</a> |
|
|
{{ end }}
|
|
<a href="{{ .SilenceURL }}">Silence</a>
|
|
</p>
|
|
{% endraw %}
|
|
|
|
# Controls the `templating.resolved-template` configuration setting.
|
|
matrix_alertmanager_receiver_config_templating_resolved_template: |-
|
|
{% raw %}
|
|
<strong><font color="green">{{ .Alert.Status | ToUpper }}</font></strong>
|
|
{{ if .Alert.Labels.name }}
|
|
{{ .Alert.Labels.name }}
|
|
{{ else if .Alert.Labels.alertname }}
|
|
{{ .Alert.Labels.alertname }}
|
|
{{ end }}
|
|
{% endraw %}
|
|
|
|
# Default matrix-alertmanager-receiver configuration template which covers the generic use case.
|
|
# You can customize it by controlling the various variables inside it.
|
|
#
|
|
# For a more advanced customization, you can extend the default (see `matrix_alertmanager_receiver_configuration_extension_yaml`)
|
|
# or completely replace this variable with your own template.
|
|
matrix_alertmanager_receiver_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}"
|
|
|
|
matrix_alertmanager_receiver_configuration_extension_yaml: |
|
|
# Your custom YAML configuration for matrix-alertmanager-receiver goes here.
|
|
# This configuration extends the default starting configuration (`matrix_alertmanager_receiver_configuration_yaml`).
|
|
#
|
|
# You can override individual variables from the default configuration, or introduce new ones.
|
|
#
|
|
# If you need something more special, you can take full control by
|
|
# completely redefining `matrix_alertmanager_receiver_configuration_yaml`.
|
|
#
|
|
# Example configuration extension follows:
|
|
#
|
|
# http:
|
|
# address: ''
|
|
|
|
matrix_alertmanager_receiver_configuration_extension: "{{ matrix_alertmanager_receiver_configuration_extension_yaml | from_yaml if matrix_alertmanager_receiver_configuration_extension_yaml | from_yaml is mapping else {} }}"
|
|
|
|
# Holds the final matrix-alertmanager-receiver configuration (a combination of the default and its extension).
|
|
# You most likely don't need to touch this variable. Instead, see `matrix_alertmanager_receiver_configuration_yaml`.
|
|
matrix_alertmanager_receiver_configuration: "{{ matrix_alertmanager_receiver_configuration_yaml | from_yaml | combine(matrix_alertmanager_receiver_configuration_extension, recursive=True) }}"
|
|
|
|
# matrix_alertmanager_receiver_restart_necessary controls whether the service
|
|
# will be restarted (when true) or merely started (when false) by the
|
|
# systemd service manager role (when conditional restart is enabled).
|
|
#
|
|
# This value is automatically computed during installation based on whether
|
|
# any configuration files, the systemd service file, or the container image changed.
|
|
# The default of `false` means "no restart needed" — appropriate when the role's
|
|
# installation tasks haven't run (e.g., due to --tags skipping them).
|
|
matrix_alertmanager_receiver_restart_necessary: false
|