Skip to content

Commit 249e2a0

Browse files
authored
Replace blackbox and nodeexporter role symlinks with copy (#261)
Signed-off-by: Jim Enright <[email protected]>
1 parent 758a71f commit 249e2a0

File tree

14 files changed

+525
-2
lines changed

14 files changed

+525
-2
lines changed

roles/blackbox

Lines changed: 0 additions & 1 deletion
This file was deleted.

roles/blackbox/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# blackbox_exporter
2+
3+
Install Blackbox Exporter
4+
5+
This role handles the download, installation, and configuration of the Prometheus Blackbox Exporter on a Linux host. The Blackbox Exporter is used to probe endpoints over various protocols, and this role ensures it is set up as a systemd service, running under a dedicated user and group, ready for configuration and use with Prometheus.
6+
7+
The role will:
8+
- Create a dedicated system user and group (`blackbox`) for the service.
9+
- Download the specified Blackbox Exporter tarball from the provided URL.
10+
- Extract the Blackbox Exporter binary to the configured binary directory (`/usr/local/bin` by default).
11+
- Set up a systemd service file for Blackbox Exporter.
12+
- Ensure the Blackbox Exporter service is running and enabled on system boot.
13+
14+
# Requirements
15+
16+
- A running `systemd` instance for service management.
17+
- Internet access on the target host to download the Blackbox Exporter tarball.
18+
- Root or `sudo` privileges are required to manage packages, users, and system services.
19+
20+
# Dependencies
21+
22+
None.
23+
24+
# Parameters
25+
26+
| Variable | Type | Required | Default | Description |
27+
| --- | --- | --- | --- | --- |
28+
| `blackbox_tarball_url` | `str` | `False` | `https://github.com/prometheus/blackbox_exporter/releases/download/v0.24.0/blackbox_exporter-0.24.0.linux-amd64.tar.gz` | URL to the Blackbox Exporter distribution archive file. |
29+
| `blackbox_directory` | `path` | `False` | `/etc/blackbox` | The directory for Blackbox Exporter configuration files. |
30+
| `blackbox_bin_directory` | `path` | `False` | `/usr/local/bin` | The directory where the Blackbox Exporter binary will be placed. |
31+
| `blackbox_tarball_file` | `str` | `False` | `blackbox.tar.gz` | The intermediate filename to use for the downloaded tarball. |
32+
| `blackbox_user` | `str` | `False` | `blackbox` | The system username under which the Blackbox Exporter service will run. |
33+
| `blackbox_group` | `str` | `False` | `blackbox` | The system group under which the Blackbox Exporter service will run. |
34+
| `blackbox_service_directory` | `path` | `False` | `/etc/systemd/system/blackbox.service` | Full path to the systemd service file for Blackbox Exporter. |
35+
36+
# Example Playbook
37+
38+
```yaml
39+
- hosts: monitoring_targets
40+
tasks:
41+
- name: Install Blackbox Exporter with default settings
42+
ansible.builtin.import_role:
43+
name: cloudera.exe.blackbox_exporter
44+
# All variables will use their defaults.
45+
46+
- name: Install a custom version of Blackbox Exporter
47+
ansible.builtin.import_role:
48+
name: cloudera.exe.blackbox_exporter
49+
vars:
50+
blackbox_tarball_url: "[https://github.com/prometheus/blackbox_exporter/releases/download/v0.25.0/blackbox_exporter-0.25.0.linux-amd64.tar.gz](https://github.com/prometheus/blackbox_exporter/releases/download/v0.25.0/blackbox_exporter-0.25.0.linux-amd64.tar.gz)"
51+
blackbox_tarball_file: "blackbox-0.25.0.tar.gz"
52+
blackbox_user: "prom_exporter"
53+
blackbox_group: "prom_exporter"
54+
```
55+
56+
# License
57+
58+
```
59+
Copyright 2025 Cloudera, Inc.
60+
61+
Licensed under the Apache License, Version 2.0 (the "License");
62+
you may not use this file except in compliance with the License.
63+
You may obtain a copy of the License at
64+
65+
https://www.apache.org/licenses/LICENSE-2.0
66+
67+
Unless required by applicable law or agreed to in writing, software
68+
distributed under the License is distributed on an "AS IS" BASIS,
69+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
70+
See the License for the specific language governing permissions and
71+
limitations under the License.
72+
```

roles/blackbox/defaults/main.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
3+
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
blackbox_tarball_url: https://github.com/prometheus/blackbox_exporter/releases/download/v0.24.0/blackbox_exporter-0.24.0.linux-amd64.tar.gz
18+
blackbox_directory: /etc/blackbox
19+
blackbox_bin_directory: /usr/local/bin
20+
blackbox_tarball_file: blackbox.tar.gz
21+
22+
blackbox_user: blackbox
23+
blackbox_group: blackbox
24+
25+
blackbox_service_directory: /etc/systemd/system/blackbox.service

roles/blackbox/handlers/main.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
- name: Start blackbox service
17+
block:
18+
- name: Reload systemd daemon
19+
ansible.builtin.systemd:
20+
daemon_reload: true
21+
22+
- name: Start Blackbox service
23+
ansible.builtin.systemd:
24+
name: blackbox
25+
state: started
26+
enabled: true
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
17+
argument_specs:
18+
main:
19+
short_description: Install Blackbox Exporter
20+
description:
21+
- Download and install the Blackbox Explorer (blackbox_exporter) for Prometheus.
22+
author: Cloudera Labs
23+
version_added: 5.0.0
24+
options:
25+
blackbox_tarball_url:
26+
description: Blackbox distribution URL
27+
type: str
28+
required: false
29+
default: https://github.com/prometheus/blackbox_exporter/releases/download/v0.24.0/blackbox_exporter-0.24.0.linux-amd64.tar.gz
30+
blackbox_directory:
31+
description: Blackbox configuration directory
32+
type: path
33+
required: false
34+
default: /etc/blackbox
35+
blackbox_bin_directory:
36+
description: Blackbox binary directory
37+
type: path
38+
required: false
39+
default: /usr/local/bin
40+
blackbox_tarball_file:
41+
description: Blackbox download file name
42+
type: str
43+
required: false
44+
default: blackbox.tar.gz
45+
blackbox_user:
46+
description: Blackbox service username
47+
type: str
48+
required: false
49+
default: blackbox
50+
blackbox_group:
51+
description: Blackbox service group
52+
type: str
53+
required: false
54+
default: blackbox
55+
blackbox_service_directory:
56+
description: Blackbox Systemd service file
57+
type: path
58+
required: false
59+
default: /etc/systemd/system/blackbox.service

roles/blackbox/tasks/main.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
- name: Create Blackbox directory
17+
ansible.builtin.file:
18+
path: "{{ blackbox_directory }}"
19+
mode: "0755"
20+
state: directory
21+
22+
- name: Create a temporary directory
23+
ansible.builtin.tempfile:
24+
state: directory
25+
register: __blackbox_tmp
26+
27+
- name: Download Blackbox tarball
28+
ansible.builtin.get_url:
29+
url: "{{ blackbox_tarball_url }}"
30+
dest: "{{ __blackbox_tmp.path }}/{{ blackbox_tarball_file }}"
31+
mode: "0755"
32+
33+
- name: Extract tarball
34+
ansible.builtin.unarchive:
35+
src: "{{ __blackbox_tmp.path }}/{{ blackbox_tarball_file }}"
36+
dest: "{{ blackbox_directory }}"
37+
extra_opts: --strip-components=1
38+
remote_src: true
39+
40+
- name: Remove the temporary directory
41+
when: __blackbox_tmp is defined
42+
ansible.builtin.file:
43+
path: "{{ __blackbox_tmp.path }}"
44+
state: absent
45+
46+
- name: Create Blackbox group
47+
ansible.builtin.group:
48+
name: "{{ blackbox_group }}"
49+
50+
- name: Create Blackbox user
51+
ansible.builtin.user:
52+
name: "{{ blackbox_user }}"
53+
system: true
54+
55+
- name: Set ownership of all files inside Blackbox directory
56+
ansible.builtin.file:
57+
path: "{{ blackbox_directory }}"
58+
owner: "{{ blackbox_user }}"
59+
group: "{{ blackbox_group }}"
60+
recurse: true
61+
62+
- name: Copy Blackbox binary to execution path
63+
ansible.builtin.copy:
64+
remote_src: true
65+
src: "{{ blackbox_directory }}/blackbox_exporter"
66+
dest: "{{ blackbox_bin_directory }}/blackbox_exporter"
67+
owner: "{{ blackbox_user }}"
68+
group: "{{ blackbox_group }}"
69+
mode: "0755"
70+
71+
- name: Create Blackbox service template
72+
ansible.builtin.template:
73+
src: blackbox.service.j2
74+
dest: "{{ blackbox_service_directory }}"
75+
mode: "0755"
76+
notify: Start blackbox service
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Unit]
2+
Description=Blackbox Exporter Service
3+
Wants=network-online.target
4+
After=network-online.target
5+
6+
[Service]
7+
Type=simple
8+
User={{ blackbox_user }}
9+
Group={{ blackbox_group }}
10+
ExecStart={{ blackbox_bin_directory }}/blackbox_exporter \
11+
--config.file={{ blackbox_directory }}/blackbox.yml
12+
13+
Restart=always
14+
15+
[Install]
16+
WantedBy=multi-user.target

roles/nodeexporter

Lines changed: 0 additions & 1 deletion
This file was deleted.

roles/nodeexporter/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# node_exporter
2+
3+
Install Node Exporter.
4+
5+
This role handles the download, installation, and configuration of the Prometheus Node Exporter on a Linux host. It ensures the Node Exporter is set up as a systemd service, running under a dedicated user and group, making it ready to expose host-level metrics for Prometheus scraping.
6+
7+
The role will:
8+
- Create a dedicated system user and group for the Node Exporter service.
9+
- Download the specified Node Exporter tarball from the provided URL.
10+
- Extract the Node Exporter binary to the configured directory.
11+
- Set up a systemd service file for Node Exporter.
12+
- Enable and start the Node Exporter service, ensuring it runs on system boot.
13+
14+
## Requirements
15+
16+
- Target host must have `systemd` for service management.
17+
- Internet access on the target host to download the Node Exporter tarball.
18+
19+
## Dependencies
20+
21+
None.
22+
23+
## Role Variables
24+
25+
| Parameter | Type | Default Value | Required | Description |
26+
|----------------------------------|------|------------------------------------------------------------------------------------|----------|-------------------------------------------------|
27+
| `node_exporter_directory` | `path`| `/etc/node_exporter` | `false` | The directory where Node Exporter will be installed. |
28+
| `node_exporter_tarball_url` | `str`| `https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz`| `false` | URL to the Node Exporter installation package (tarball). |
29+
| `node_exporter_tarball_file` | `str`| `node_exporter.tar.gz` | `false` | The intermediate filename to use for the downloaded tarball. |
30+
| `node_exporter_service_directory`| `path`| `/etc/systemd/system/node_exporter.service` | `false` | Full path to the systemd service file for Node Exporter. |
31+
| `node_exporter_user` | `str`| `node_exporter` | `false` | The system username under which the Node Exporter service will run. |
32+
| `node_exporter_group` | `str`| `node_exporter` | `false` | The system group under which the Node Exporter service will run. |
33+
34+
## Examples
35+
36+
```yaml
37+
- name: Install Node Exporter with default configuration
38+
ansible.builtin.import_role:
39+
name: node_exporter
40+
# No variables needed here as defaults will be used
41+
42+
- name: Install Node Exporter v1.8.0
43+
ansible.builtin.import_role:
44+
name: node_exporter
45+
vars:
46+
node_exporter_tarball_url: "https://github.com/prometheus/node_exporter/releases/download/v1.8.0/node_exporter-1.8.0.linux-amd64.tar.gz"
47+
node_exporter_tarball_file: "node_exporter-1.8.0.tar.gz" # Update filename for clarity
48+
49+
- name: Install Node Exporter with custom paths and user
50+
ansible.builtin.import_role:
51+
name: node_exporter
52+
vars:
53+
node_exporter_directory: "/opt/monitoring/node_exporter"
54+
node_exporter_service_directory: "/usr/lib/systemd/system/node_exporter.service" # Common location on some distros
55+
node_exporter_user: "prometheus_exporter"
56+
node_exporter_group: "prometheus_exporter"
57+
```
58+
59+
## License
60+
61+
```
62+
Copyright 2025 Cloudera, Inc.
63+
64+
Licensed under the Apache License, Version 2.0 (the "License");
65+
you may not use this file except in compliance with the License.
66+
You may obtain a copy of the License at
67+
68+
https://www.apache.org/licenses/LICENSE-2.0
69+
70+
Unless required by applicable law or agreed to in writing, software
71+
distributed under the License is distributed on an "AS IS" BASIS,
72+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
73+
See the License for the specific language governing permissions and
74+
limitations under the License.
75+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
3+
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
node_exporter_directory: /etc/node_exporter
18+
node_exporter_tarball_url: https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
19+
node_exporter_tarball_file: node_exporter.tar.gz
20+
node_exporter_service_directory: /etc/systemd/system/node_exporter.service
21+
22+
node_exporter_user: nodeexporter
23+
node_exporter_group: nodeexporter

0 commit comments

Comments
 (0)