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 (#126)
Browse files Browse the repository at this point in the history
* add option to propagate binaries without access to internet

Same as cloudalchemy/ansible-alertmanager#83 and cloudalchemy/ansible-prometheus#239 but for Node exporter.

* Fix typo

* Fix molecule/alternative/prepare.yml

* Fix molecule/alternative/prepare.yml again :D

* Fix _checksum not being defined

* Use double quotes for consistency

* Fix typo...

* Fix c/p error
  • Loading branch information
DaazKu authored and paulfantom committed Dec 5, 2019
1 parent c4d8c0e commit efd7bc1
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 35 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults
| Name | Default Value | Description |
| -------------- | ------------- | -----------------------------------|
| `node_exporter_version` | 0.18.1 | Node exporter package version. Also accepts latest as parameter. |
| `node_exporter_binaries_local_dir` | "" | Allows to use local packages instead of ones distributed on github. As parameter it takes a directory where `node_exporter` binary is stored on host on which ansible is ran. This overrides `node_exporter_version` parameter |
| `node_exporter_web_listen_address` | "0.0.0.0:9100" | Address on which node exporter will listen |
| `node_exporter_system_group` | "node-exp" | System group used to run node_exporter |
| `node_exporter_system_user` | "node-exp" | System user used to run node_exporter |
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 @@
---
node_exporter_version: 0.18.1
node_exporter_binary_local_dir: ""
node_exporter_web_listen_address: "0.0.0.0:9100"

node_exporter_system_group: "node-exp"
Expand Down
1 change: 1 addition & 0 deletions molecule/alternative/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
roles:
- ansible-node-exporter
vars:
node_exporter_binary_local_dir: "/tmp/node_exporter-linux-amd64"
node_exporter_system_group: "root"
node_exporter_system_user: "root"
node_exporter_textfile_dir: ""
Expand Down
36 changes: 34 additions & 2 deletions molecule/alternative/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
---
- name: Prepare
hosts: all
hosts: localhost
gather_facts: false
tasks: []
vars:
go_arch: amd64
node_exporter_version: 0.18.1
tasks:
- name: Download node_exporter binary to local folder
become: false
get_url:
url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
register: _download_binary
until: _download_binary is succeeded
retries: 5
delay: 2
run_once: true
check_mode: false

- name: Unpack node_exporter binary
become: false
unarchive:
src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp"
creates: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}/node_exporter"
run_once: true
check_mode: false

- name: link to node_exporter binaries directory
become: false
file:
src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-amd64"
dest: "/tmp/node_exporter-linux-amd64"
state: link
run_once: true
check_mode: false
58 changes: 35 additions & 23 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,46 @@
home: /
when: node_exporter_system_user != "root"

- name: Download node_exporter binary to local folder
become: false
get_url:
url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
checksum: "sha256:{{ node_exporter_checksum }}"
register: _download_binary
until: _download_binary is succeeded
retries: 5
delay: 2
delegate_to: localhost
check_mode: false
- block:
- name: Download node_exporter binary to local folder
become: false
get_url:
url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
checksum: "sha256:{{ node_exporter_checksum }}"
register: _download_binary
until: _download_binary is succeeded
retries: 5
delay: 2
delegate_to: localhost
check_mode: false

- name: Unpack node_exporter binary
become: false
unarchive:
src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp"
creates: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}/node_exporter"
delegate_to: localhost
check_mode: false

- name: Unpack node_exporter binary
become: false
unarchive:
src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp"
creates: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}/node_exporter"
delegate_to: localhost
check_mode: false
- name: Propagate node_exporter binaries
copy:
src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}/node_exporter"
dest: "/usr/local/bin/node_exporter"
mode: 0755
owner: root
group: root
notify: restart node_exporter
when: not ansible_check_mode
when: node_exporter_binary_local_dir | length == 0

- name: Propagate node_exporter binaries
- name: propagate locally distributed node_exporter binary
copy:
src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}/node_exporter"
src: "{{ node_exporter_binary_local_dir }}/node_exporter"
dest: "/usr/local/bin/node_exporter"
mode: 0755
owner: root
group: root
when: node_exporter_binary_local_dir | length > 0
notify: restart node_exporter
when: not ansible_check_mode
25 changes: 15 additions & 10 deletions tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,22 @@
- name: "Set node_exporter version to {{ _latest_release.json.tag_name[1:] }}"
set_fact:
node_exporter_version: "{{ _latest_release.json.tag_name[1:] }}"
when: node_exporter_version == "latest"
when:
- node_exporter_version == "latest"
- node_exporter_binary_local_dir | length == 0
delegate_to: localhost
run_once: true

- name: Get checksum list from github
set_fact:
_checksums: "{{ lookup('url', 'https://github.com/prometheus/node_exporter/releases/download/v' + node_exporter_version + '/sha256sums.txt', wantlist=True) | list }}"
run_once: true
- block:
- name: Get checksum list from github
set_fact:
_checksums: "{{ lookup('url', 'https://github.com/prometheus/node_exporter/releases/download/v' + node_exporter_version + '/sha256sums.txt', wantlist=True) | list }}"
run_once: true

- name: "Get checksum for {{ go_arch }} architecture"
set_fact:
node_exporter_checksum: "{{ item.split(' ')[0] }}"
with_items: "{{ _checksums }}"
when: "('linux-' + go_arch + '.tar.gz') in item"
- name: "Get checksum for {{ go_arch }} architecture"
set_fact:
node_exporter_checksum: "{{ item.split(' ')[0] }}"
with_items: "{{ _checksums }}"
when:
- "('linux-' + go_arch + '.tar.gz') in item"
when: node_exporter_binary_local_dir | length == 0

0 comments on commit efd7bc1

Please sign in to comment.