-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check installed node_exporter version instead of always downloading
- Loading branch information
Showing
4 changed files
with
96 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#! python3 | ||
|
||
import subprocess | ||
import sys | ||
import re | ||
|
||
# compile regex for installed node_exporter version | ||
pattern = re.compile(r"node_exporter, version (\d\.\d\.\d)") | ||
|
||
# check current node_exporter | ||
node_exporter = subprocess.check_output(["/opt/node_exporter/node_exporter", "--version"]).decode("utf-8") | ||
|
||
# use regex to find installed version | ||
result = pattern.match(node_exporter) | ||
|
||
if result: | ||
# print only the version, without newline otherwise ansible will store the newline | ||
print(result[1], end="") | ||
else: | ||
print("not_installed", end="") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
- name: Detected Architecture | ||
ansible.builtin.debug: | ||
var: go_arch | ||
|
||
- name: Download node_exporter | ||
ansible.builtin.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: /opt/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz | ||
mode: '0644' | ||
owner: root | ||
group: root | ||
|
||
- name: Unpack node_exporter | ||
ansible.builtin.unarchive: | ||
src: /opt/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz | ||
dest: /opt | ||
remote_src: true | ||
mode: '0644' | ||
owner: root | ||
group: root | ||
when: not ansible_check_mode | ||
|
||
- name: Delete node_exporter archive | ||
ansible.builtin.file: | ||
path: /opt/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz | ||
state: absent | ||
|
||
- name: Stop node_exporter service | ||
ansible.builtin.systemd: | ||
daemon-reload: true | ||
enabled: true | ||
name: node_exporter | ||
state: stopped | ||
|
||
- name: Move node exporter to target directory | ||
ansible.builtin.copy: | ||
remote_src: true | ||
src: /opt/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}/ | ||
dest: /opt/node_exporter/ | ||
force: true | ||
mode: '0744' | ||
owner: prometheus | ||
group: prometheus | ||
|
||
- name: Delete node_exporter directory | ||
ansible.builtin.file: | ||
path: /opt/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}/ | ||
state: absent | ||
|
||
- name: Adjust node_exporter permissions | ||
ansible.builtin.file: | ||
path: /opt/node_exporter/node_exporter | ||
owner: prometheus | ||
group: prometheus | ||
mode: '0744' | ||
state: file | ||
|
||
- name: Start node_exporter service | ||
ansible.builtin.systemd: | ||
daemon-reload: true | ||
enabled: true | ||
name: node_exporter | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters