Introduction
Blackbox Exporter is a component of the Prometheus monitoring system that allows you to perform active monitoring of network endpoints. It is designed to probe targets and collect metrics related to their availability, responsiveness, and other network-level characteristics.
Prerequisites
- Up and running ubuntu 22.04 LTS machine.
- Basic knowledge in linux commands.
- Internet connectivity.
- Ansible should be installed.
We can use the given link to install Ansible on Ubuntu 22.04 LTS Linux machine.
In this post, We will show you how to deploy Blackbox Exporter using Ansible-play on ubuntu 22.04 LTS Linux machine.
Step 1: Create an Ansible inventory file
To deploy Blackbox Exporter using Ansible on Ubuntu 22.04 LTS, you can create an Ansible playbook that installs and configures Blackbox Exporter. Blackbox Exporter is a tool for probing endpoints over HTTP, HTTPS, DNS, TCP, and ICMP to collect metrics.
To create ansible playbook
sudo nano deploy_blackbox_exporter.yml
Paste the following ansible tasks.
---
- name: Deploy Blackbox Exporter
hosts: your_target_servers
become: true
tasks:
- name: Create Blackbox Exporter user
user:
name: blackbox_exporter
system: yes
shell: /bin/false
- name: Download and extract Blackbox Exporter
get_url:
url: "https://github.com/prometheus/blackbox_exporter/releases/download/v0.21.0/blackbox_exporter-0.21.0.linux-amd64.tar.gz"
dest: "/tmp/blackbox_exporter.tar.gz"
- name: Extract Blackbox Exporter
ansible.builtin.unarchive:
src: "/tmp/blackbox_exporter.tar.gz"
dest: "/opt/"
- name: Set permissions and ownership
file:
path: "/opt/blackbox_exporter-0.21.0.linux-amd64/blackbox_exporter"
mode: "0755"
owner: "blackbox_exporter"
group: "blackbox_exporter"
- name: Create Blackbox Exporter configuration directory
file:
path: "/etc/blackbox_exporter"
state: directory
mode: "0755"
owner: "blackbox_exporter"
group: "blackbox_exporter"
- name: Copy Blackbox Exporter configuration file
copy:
src: "blackbox.yml"
dest: "/etc/blackbox_exporter/blackbox.yml"
owner: "blackbox_exporter"
group: "blackbox_exporter"
mode: "0644"
- name: Create Blackbox Exporter systemd service
systemd:
name: blackbox_exporter
enabled: yes
state: started
daemon_reload: yes
daemon_reexec: yes
scope: user
user: blackbox_exporter
exec_start: "/opt/blackbox_exporter-0.21.0.linux-amd64/blackbox_exporter --config.file=/etc/blackbox_exporter/blackbox.yml"
This playbook does the following:
- Creates a user named blackbox_exporter for running Blackbox Exporter.
- Downloads the Blackbox Exporter binary from the official GitHub release page.
- Extracts the Blackbox Exporter tarball to the /opt/ directory.
- Sets the necessary permissions and ownership for the Blackbox Exporter binary.
- Creates the Blackbox Exporter configuration directory and copies the configuration file (
blackbox.yml
) to the appropriate location - Creates a systemd service for Blackbox Exporter and starts it.
Make sure to replace your_target_servers
with the target servers or server group where you want to install Blackbox Exporter.
Create an Ansible inventory file (e.g., inventory.ini
) with the IP addresses or hostnames of your target servers.
Step 2: Run the Ansible playbook
We need to execute the following command to deploy the ansible playbook.
ansible-playbook -i inventory.ini deploy_blackbox_exporter.yml
Adjust the version number in the URL to the latest version available on the Blackbox Exporter GitHub releases page. Additionally, provide a valid blackbox.yml
configuration file suitable for your environment.
You can use the end to end Prometheus Blackbox setup and configuration by using given link 🙂
Conclusion
We have successfully deployed Blackbox using Ansible Playbook on Ubuntu 22.04 LTS. If you are still having issues, please leave a comment below.