From cd7c7cc26f058235674db2b593877a09bfbdad82 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Thu, 16 Mar 2023 12:35:26 +0100 Subject: [PATCH] Alertmanager: add `skip_install` variable This is similar to prometheus_skip_install variable and does what the name says: when set, it won't try to re-download alertmanager binaries Signed-off-by: Christian Brabandt --- roles/alertmanager/README.md | 1 + roles/alertmanager/defaults/main.yml | 1 + roles/alertmanager/meta/argument_specs.yml | 4 ++++ roles/alertmanager/tasks/install.yml | 8 ++++++-- roles/alertmanager/tasks/preflight.yml | 2 ++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/roles/alertmanager/README.md b/roles/alertmanager/README.md index 3b0888878..1f8f20853 100644 --- a/roles/alertmanager/README.md +++ b/roles/alertmanager/README.md @@ -19,6 +19,7 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults | Name | Default Value | Description | | -------------- | ------------- | -----------------------------------| | `alertmanager_version` | 0.21.0 | Alertmanager package version. Also accepts `latest` as parameter. | +| `alertmanager_skip_install` | false | Alertmanager installation tasks gets skipped when set to true. | | `alertmanager_binary_local_dir` | "" | Allows to use local packages instead of ones distributed on github. As parameter it takes a directory where `alertmanager` AND `amtool` binaries are stored on host on which ansible is ran. This overrides `alertmanager_version` parameter | | `alertmanager_binary_url` | `https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz` | URL of the alertmanager binaries .tar.gz file | | `alertmanager_checksums_url` | `https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/sha256sums.txt` | URL of the alertmanager checksums file | diff --git a/roles/alertmanager/defaults/main.yml b/roles/alertmanager/defaults/main.yml index 18cd7118b..96ac713d2 100644 --- a/roles/alertmanager/defaults/main.yml +++ b/roles/alertmanager/defaults/main.yml @@ -4,6 +4,7 @@ alertmanager_binary_local_dir: '' alertmanager_binary_url: "https://github.com/{{ _alertmanager_repo }}/releases/download/v{{ alertmanager_version }}/\ alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz" alertmanager_checksums_url: "https://github.com/{{ _alertmanager_repo }}/releases/download/v{{ alertmanager_version }}/sha256sums.txt" +alertmanager_skip_install: false alertmanager_config_dir: /etc/alertmanager alertmanager_db_dir: /var/lib/alertmanager diff --git a/roles/alertmanager/meta/argument_specs.yml b/roles/alertmanager/meta/argument_specs.yml index a10326d58..0d5d8c797 100644 --- a/roles/alertmanager/meta/argument_specs.yml +++ b/roles/alertmanager/meta/argument_specs.yml @@ -11,6 +11,10 @@ argument_specs: alertmanager_version: description: "Alertmanager package version. Also accepts `latest` as parameter." default: 0.21.0 + alertmanager_skip_install: + description: "Alertmanager installation tasks gets skipped when set to true." + type: bool + default: false alertmanager_binary_local_dir: description: - "Allows to use local packages instead of ones distributed on github." diff --git a/roles/alertmanager/tasks/install.yml b/roles/alertmanager/tasks/install.yml index e1a391550..bfb8995c1 100644 --- a/roles/alertmanager/tasks/install.yml +++ b/roles/alertmanager/tasks/install.yml @@ -27,7 +27,9 @@ - "{{ _alertmanager_amtool_config_dir }}" - name: Get alertmanager binary - when: alertmanager_binary_local_dir | length == 0 + when: + - alertmanager_binary_local_dir | length == 0 + - not alertmanager_skip_install block: - name: Download alertmanager binary to local folder @@ -78,6 +80,8 @@ with_items: - alertmanager - amtool - when: alertmanager_binary_local_dir | length > 0 + when: + - alertmanager_binary_local_dir | length > 0 + - not alertmanager_skip_install notify: - restart alertmanager diff --git a/roles/alertmanager/tasks/preflight.yml b/roles/alertmanager/tasks/preflight.yml index 00e0c6b44..4bfdad718 100644 --- a/roles/alertmanager/tasks/preflight.yml +++ b/roles/alertmanager/tasks/preflight.yml @@ -29,10 +29,12 @@ when: - alertmanager_version == "latest" - alertmanager_binary_local_dir | length == 0 + - not alertmanager_skip_install - name: Get alertmanager binary checksum when: - alertmanager_binary_local_dir | length == 0 + - not alertmanager_skip_install block: - name: "Get checksum list" ansible.builtin.set_fact: