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

Commit

Permalink
add option to propagate binaries without access to internet
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfantom committed Aug 21, 2019
1 parent 2cd910d commit dc7d706
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 27 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ 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. Also accepts `latest` as parameter. |
| `alertmanager_version` | 0.18.0 | Alertmanager package version. Also accepts `latest` as parameter. |
| `alertmanager_binaries_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_web_listen_address` | 0.0.0.0:9093 | Address on which alertmanager will be listening |
| `alertmanager_web_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
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
alertmanager_version: 0.18.0
alertmanager_binary_local_dir: ''

alertmanager_config_dir: /etc/alertmanager
alertmanager_db_dir: /var/lib/alertmanager
Expand Down
2 changes: 1 addition & 1 deletion molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ provisioner:
name: ansible-lint
playbooks:
create: ../default/create.yml
prepare: ../default/prepare.yml
prepare: prepare.yml
converge: playbook.yml
destroy: ../default/destroy.yml
scenario:
Expand Down
1 change: 1 addition & 0 deletions molecule/alternative/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
roles:
- ansible-alertmanager
vars:
alertmanager_binary_local_dir: '/tmp/alertmanager-0.18.0.linux-amd64'
alertmanager_config_dir: /opt/am/etc
alertmanager_db_dir: /opt/am/lib
alertmanager_web_listen_address: '127.0.0.1:9093'
Expand Down
25 changes: 25 additions & 0 deletions molecule/alternative/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: Prepare
hosts: localhost
gather_facts: false
tasks:
- name: download alertmanager binary to local folder
become: false
get_url:
url: "https://github.com/prometheus/alertmanager/releases/download/v0.18.0/alertmanager-0.18.0.linux-amd64.tar.gz"
dest: "/tmp/alertmanager-0.18.0.linux-amd64.tar.gz"
register: _download_archive
until: _download_archive is succeeded
retries: 5
delay: 2
run_once: true
check_mode: false

- name: unpack alertmanager binaries
become: false
unarchive:
src: "/tmp/alertmanager-0.18.0.linux-amd64.tar.gz"
dest: "/tmp"
creates: "/tmp/alertmanager-0.18.0.linux-amd64/alertmanager"
run_once: true
check_mode: false
62 changes: 39 additions & 23 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,55 @@
- "{{ alertmanager_config_dir }}/templates"
- "{{ alertmanager_db_dir }}"

- name: download alertmanager binary to local folder
become: false
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 # <-- this can't be set due to multi-arch support
delegate_to: localhost
check_mode: false
- block:
- name: download alertmanager binary to local folder
become: false
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 # <-- 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: 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 official alertmanager and amtool binaries
copy:
src: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}/{{ item }}"
dest: "/usr/local/bin/{{ item }}"
mode: 0755
owner: root
group: root
with_items:
- alertmanager
- amtool
notify:
- restart alertmanager
when: alertmanager_binary_local_dir | length == 0

- name: propagate alertmanager and amtool binaries
- name: propagate locally distributed alertmanager and amtool binaries
copy:
src: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}/{{ item }}"
src: "{{ alertmanager_binary_local_dir }}/{{ item }}"
dest: "/usr/local/bin/{{ item }}"
mode: 0755
owner: root
group: root
with_items:
- alertmanager
- amtool
when: alertmanager_binary_local_dir | length > 0
notify:
- restart alertmanager

Expand Down
8 changes: 6 additions & 2 deletions tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@
- 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"
when:
- alertmanager_version == "latest"
- alertmanager_binary_local_path | length == 0

- 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"
when:
- "('linux-' + go_arch + '.tar.gz') in item"
- alertmanager_binary_local_dir | length == 0

- name: Backward compatibility of variable [part 1]
set_fact:
Expand Down

0 comments on commit dc7d706

Please sign in to comment.