Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
Tuan-Dat Tran
2024-10-08 11:31:26 +02:00
parent 0c1a8a95f2
commit 5d0f56ce38
15 changed files with 49 additions and 38 deletions

View File

@@ -1,7 +1,7 @@
---
- name: Determine latest GitHub release (local)
delegate_to: localhost
uri:
ansible.builtin.uri:
url: "https://api.github.com/repos/prometheus/node_exporter/releases/{{ version }}"
body_format: json
register: _github_release
@@ -9,10 +9,10 @@
retries: 3
- name: Set version
set_fact:
ansible.builtin.set_fact:
tag: "{{ _github_release.json.tag_name
| regex_replace('^v?([0-9\\.]+)$', '\\1') }}"
- name: Set download_url
set_fact:
ansible.builtin.set_fact:
download_url: "https://github.com/prometheus/node_exporter/releases/download/v{{ tag }}/node_exporter-{{ tag }}.linux-{{ go_arch }}.tar.gz"

View File

@@ -1,29 +1,29 @@
---
- name: Download/Extract "{{ download_url }}"
unarchive:
ansible.builtin.unarchive:
src: "{{ download_url }}"
dest: /tmp/
remote_src: true
mode: 755
mode: "755"
- name: Move node_exporter into path
copy:
ansible.builtin.copy:
src: "/tmp/node_exporter-{{ tag }}.linux-{{ go_arch }}/node_exporter"
dest: "{{ bin_path }}"
mode: 755
mode: "755"
remote_src: true
become: true
- name: Create node_exporter user.
user:
ansible.builtin.user:
name: node_exporter
shell: /sbin/nologin
state: present
become: true
- name: Copy the node_exporter systemd unit file.
template:
ansible.builtin.template:
src: node_exporter.service.j2
dest: /etc/systemd/system/node_exporter.service
mode: 0644
mode: "644"
become: true

View File

@@ -1,3 +1,6 @@
- include_tasks: get_version.yml
- include_tasks: install.yml
- include_tasks: systemd.yml
- name: Get Version
ansible.builtin.include_tasks: get_version.yml
- name: Install
ansible.builtin.include_tasks: install.yml
- name: Setup Service
ansible.builtin.include_tasks: systemd.yml

View File

@@ -1,6 +1,6 @@
---
- name: Ensure node_exporter is running and enabled at boot.
service:
ansible.builtin.service:
name: node_exporter
state: started
daemon_reload: true