Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion roles/blackbox

This file was deleted.

72 changes: 72 additions & 0 deletions roles/blackbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# blackbox_exporter

Install Blackbox Exporter

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.

The role will:
- Create a dedicated system user and group (`blackbox`) for the service.
- Download the specified Blackbox Exporter tarball from the provided URL.
- Extract the Blackbox Exporter binary to the configured binary directory (`/usr/local/bin` by default).
- Set up a systemd service file for Blackbox Exporter.
- Ensure the Blackbox Exporter service is running and enabled on system boot.

# Requirements

- A running `systemd` instance for service management.
- Internet access on the target host to download the Blackbox Exporter tarball.
- Root or `sudo` privileges are required to manage packages, users, and system services.

# Dependencies

None.

# Parameters

| Variable | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `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. |
| `blackbox_directory` | `path` | `False` | `/etc/blackbox` | The directory for Blackbox Exporter configuration files. |
| `blackbox_bin_directory` | `path` | `False` | `/usr/local/bin` | The directory where the Blackbox Exporter binary will be placed. |
| `blackbox_tarball_file` | `str` | `False` | `blackbox.tar.gz` | The intermediate filename to use for the downloaded tarball. |
| `blackbox_user` | `str` | `False` | `blackbox` | The system username under which the Blackbox Exporter service will run. |
| `blackbox_group` | `str` | `False` | `blackbox` | The system group under which the Blackbox Exporter service will run. |
| `blackbox_service_directory` | `path` | `False` | `/etc/systemd/system/blackbox.service` | Full path to the systemd service file for Blackbox Exporter. |

# Example Playbook

```yaml
- hosts: monitoring_targets
tasks:
- name: Install Blackbox Exporter with default settings
ansible.builtin.import_role:
name: cloudera.exe.blackbox_exporter
# All variables will use their defaults.

- name: Install a custom version of Blackbox Exporter
ansible.builtin.import_role:
name: cloudera.exe.blackbox_exporter
vars:
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)"
blackbox_tarball_file: "blackbox-0.25.0.tar.gz"
blackbox_user: "prom_exporter"
blackbox_group: "prom_exporter"
```

# License

```
Copyright 2025 Cloudera, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
25 changes: 25 additions & 0 deletions roles/blackbox/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---

# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

blackbox_tarball_url: https://github.com/prometheus/blackbox_exporter/releases/download/v0.24.0/blackbox_exporter-0.24.0.linux-amd64.tar.gz
blackbox_directory: /etc/blackbox
blackbox_bin_directory: /usr/local/bin
blackbox_tarball_file: blackbox.tar.gz

blackbox_user: blackbox
blackbox_group: blackbox

blackbox_service_directory: /etc/systemd/system/blackbox.service
26 changes: 26 additions & 0 deletions roles/blackbox/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
- name: Start blackbox service
block:
- name: Reload systemd daemon
ansible.builtin.systemd:
daemon_reload: true

- name: Start Blackbox service
ansible.builtin.systemd:
name: blackbox
state: started
enabled: true
59 changes: 59 additions & 0 deletions roles/blackbox/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---

argument_specs:
main:
short_description: Install Blackbox Exporter
description:
- Download and install the Blackbox Explorer (blackbox_exporter) for Prometheus.
author: Cloudera Labs
version_added: 5.0.0
options:
blackbox_tarball_url:
description: Blackbox distribution URL
type: str
required: false
default: https://github.com/prometheus/blackbox_exporter/releases/download/v0.24.0/blackbox_exporter-0.24.0.linux-amd64.tar.gz
blackbox_directory:
description: Blackbox configuration directory
type: path
required: false
default: /etc/blackbox
blackbox_bin_directory:
description: Blackbox binary directory
type: path
required: false
default: /usr/local/bin
blackbox_tarball_file:
description: Blackbox download file name
type: str
required: false
default: blackbox.tar.gz
blackbox_user:
description: Blackbox service username
type: str
required: false
default: blackbox
blackbox_group:
description: Blackbox service group
type: str
required: false
default: blackbox
blackbox_service_directory:
description: Blackbox Systemd service file
type: path
required: false
default: /etc/systemd/system/blackbox.service
76 changes: 76 additions & 0 deletions roles/blackbox/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: Create Blackbox directory
ansible.builtin.file:
path: "{{ blackbox_directory }}"
mode: "0755"
state: directory

- name: Create a temporary directory
ansible.builtin.tempfile:
state: directory
register: __blackbox_tmp

- name: Download Blackbox tarball
ansible.builtin.get_url:
url: "{{ blackbox_tarball_url }}"
dest: "{{ __blackbox_tmp.path }}/{{ blackbox_tarball_file }}"
mode: "0755"

- name: Extract tarball
ansible.builtin.unarchive:
src: "{{ __blackbox_tmp.path }}/{{ blackbox_tarball_file }}"
dest: "{{ blackbox_directory }}"
extra_opts: --strip-components=1
remote_src: true

- name: Remove the temporary directory
when: __blackbox_tmp is defined
ansible.builtin.file:
path: "{{ __blackbox_tmp.path }}"
state: absent

- name: Create Blackbox group
ansible.builtin.group:
name: "{{ blackbox_group }}"

- name: Create Blackbox user
ansible.builtin.user:
name: "{{ blackbox_user }}"
system: true

- name: Set ownership of all files inside Blackbox directory
ansible.builtin.file:
path: "{{ blackbox_directory }}"
owner: "{{ blackbox_user }}"
group: "{{ blackbox_group }}"
recurse: true

- name: Copy Blackbox binary to execution path
ansible.builtin.copy:
remote_src: true
src: "{{ blackbox_directory }}/blackbox_exporter"
dest: "{{ blackbox_bin_directory }}/blackbox_exporter"
owner: "{{ blackbox_user }}"
group: "{{ blackbox_group }}"
mode: "0755"

- name: Create Blackbox service template
ansible.builtin.template:
src: blackbox.service.j2
dest: "{{ blackbox_service_directory }}"
mode: "0755"
notify: Start blackbox service
16 changes: 16 additions & 0 deletions roles/blackbox/templates/blackbox.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Blackbox Exporter Service
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User={{ blackbox_user }}
Group={{ blackbox_group }}
ExecStart={{ blackbox_bin_directory }}/blackbox_exporter \
--config.file={{ blackbox_directory }}/blackbox.yml

Restart=always

[Install]
WantedBy=multi-user.target
1 change: 0 additions & 1 deletion roles/nodeexporter

This file was deleted.

75 changes: 75 additions & 0 deletions roles/nodeexporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# node_exporter

Install Node Exporter.

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.

The role will:
- Create a dedicated system user and group for the Node Exporter service.
- Download the specified Node Exporter tarball from the provided URL.
- Extract the Node Exporter binary to the configured directory.
- Set up a systemd service file for Node Exporter.
- Enable and start the Node Exporter service, ensuring it runs on system boot.

## Requirements

- Target host must have `systemd` for service management.
- Internet access on the target host to download the Node Exporter tarball.

## Dependencies

None.

## Role Variables

| Parameter | Type | Default Value | Required | Description |
|----------------------------------|------|------------------------------------------------------------------------------------|----------|-------------------------------------------------|
| `node_exporter_directory` | `path`| `/etc/node_exporter` | `false` | The directory where Node Exporter will be installed. |
| `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). |
| `node_exporter_tarball_file` | `str`| `node_exporter.tar.gz` | `false` | The intermediate filename to use for the downloaded tarball. |
| `node_exporter_service_directory`| `path`| `/etc/systemd/system/node_exporter.service` | `false` | Full path to the systemd service file for Node Exporter. |
| `node_exporter_user` | `str`| `node_exporter` | `false` | The system username under which the Node Exporter service will run. |
| `node_exporter_group` | `str`| `node_exporter` | `false` | The system group under which the Node Exporter service will run. |

## Examples

```yaml
- name: Install Node Exporter with default configuration
ansible.builtin.import_role:
name: node_exporter
# No variables needed here as defaults will be used

- name: Install Node Exporter v1.8.0
ansible.builtin.import_role:
name: node_exporter
vars:
node_exporter_tarball_url: "https://github.com/prometheus/node_exporter/releases/download/v1.8.0/node_exporter-1.8.0.linux-amd64.tar.gz"
node_exporter_tarball_file: "node_exporter-1.8.0.tar.gz" # Update filename for clarity

- name: Install Node Exporter with custom paths and user
ansible.builtin.import_role:
name: node_exporter
vars:
node_exporter_directory: "/opt/monitoring/node_exporter"
node_exporter_service_directory: "/usr/lib/systemd/system/node_exporter.service" # Common location on some distros
node_exporter_user: "prometheus_exporter"
node_exporter_group: "prometheus_exporter"
```

## License

```
Copyright 2025 Cloudera, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
23 changes: 23 additions & 0 deletions roles/nodeexporter/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

node_exporter_directory: /etc/node_exporter
node_exporter_tarball_url: https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
node_exporter_tarball_file: node_exporter.tar.gz
node_exporter_service_directory: /etc/systemd/system/node_exporter.service

node_exporter_user: nodeexporter
node_exporter_group: nodeexporter
Loading
Loading