Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
propagate support for 'latest' version specifier from ansible-prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfantom committed Jun 14, 2019
1 parent 3cdefb7 commit e3be79b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults

| Name | Default Value | Description |
| -------------- | ------------- | -----------------------------------|
| `alertmanager_version` | 0.16.1 | Alertmanager package version |
| `alertmanager_version` | 0.16.1 | Alertmanager package version. Also accepts `latest` as parameter. |
| `alertmanager_listen_address` | '0.0.0.0:9093' | Address on which alertmanager will be listening |
| `alertmanager_external_url` | 'http://localhost:9093/' | External address on which alertmanager is available. Useful when behind reverse proxy. Ex. example.org/alertmanager |
| `alertmanager_config_dir` | /etc/alertmanager | Path to directory with alertmanager configuration |
Expand Down
39 changes: 19 additions & 20 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,34 @@

- name: download alertmanager binary to local folder
become: false
unarchive:
src: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz"
dest: "/tmp"
remote_src: true
creates: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/alertmanager"
register: _download_binary
until: _download_binary is succeeded
get_url:
url: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz"
checksum: "sha256:{{ alertmanager_checksum }}"
register: _download_archive
until: _download_archive is succeeded
retries: 5
delay: 2
# run_once: true
# run_once: true # <-- this can't be set due to multi-arch support
delegate_to: localhost
check_mode: false

- name: unpack alertmanager binaries
become: false
unarchive:
src: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp"
creates: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}/alertmanager"
delegate_to: localhost
check_mode: false

- name: propagate alertmanager and amtool binaries
copy:
src: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/{{ item }}"
src: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}/{{ item }}"
dest: "/usr/local/bin/{{ item }}"
mode: 0755
owner: alertmanager
group: alertmanager
owner: root
group: root
with_items:
- alertmanager
- amtool
Expand Down Expand Up @@ -76,12 +84,3 @@
when:
- ansible_version.full is version_compare('2.4', '>=')
- ansible_selinux.status == "enabled"

- name: remove alertmanager binaries from old location
file:
path: "{{ item }}"
state: absent
with_items:
- /opt/alertmanager/alertmanager
- /opt/alertmanager/amtool
- /opt/alertmanager
45 changes: 45 additions & 0 deletions tasks/preflight.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
---
- name: Assert usage of systemd as an init system
assert:
that: ansible_service_mgr == 'systemd'
msg: "This module only works with systemd"

- name: Get systemd version
command: systemctl --version
changed_when: false
check_mode: false
register: __systemd_version
tags:
- skip_ansible_lint

- name: Set systemd version fact
set_fact:
alertmanager_systemd_version: "{{ __systemd_version.stdout_lines[0].split(' ')[-1] }}"

- block:
- name: Get latest release
uri:
url: "https://api.github.com/repos/prometheus/alertmanager/releases/latest"
method: GET
return_content: true
status_code: 200
body_format: json
validate_certs: false
user: "{{ lookup('env', 'GH_USER') | default(omit) }}"
password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}"
no_log: true
register: _latest_release
until: _latest_release.status == 200
retries: 5

- name: "Set prometheus version to {{ _latest_release.json.tag_name[1:] }}"
set_fact:
alertmanager_version: "{{ _latest_release.json.tag_name[1:] }}"
when: alertmanager_version == "latest"

- name: "Get checksum for {{ go_arch }} architecture"
set_fact:
alertmanager_checksum: "{{ item.split(' ')[0] }}"
with_items:
- "{{ lookup('url', 'https://github.com/prometheus/alertmanager/releases/download/v' + alertmanager_version + '/sha256sums.txt', wantlist=True) | list }}"
when: "('linux-' + go_arch + '.tar.gz') in item"

- name: Backward compatibility of variable [part 1]
set_fact:
alertmanager_config_flags_extra: "{{ alertmanager_cli_flags }}"
Expand Down
2 changes: 2 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ go_arch_map:
aarch64: 'arm64'
armv7l: 'armv7'
armv6l: 'armv6'

go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"

0 comments on commit e3be79b

Please sign in to comment.