r/blackbox-exporter: Deploy blackbox_exporter

The Prometheus *blackbox_exporter* is a tool that can perform arbitrary,
generic ICMP, TCP, or HTTP "probes" against external services.  This is
useful for applications that do not export their own metrics, and for
evaluating the health of protocol-level operations (e.g. TLS
certificate expiration).

The *blackbox-exporter* Ansible role installs and configures the
Blackbox Exporter on the target system.  It fetches the specified binary
release from Github and copies it to the remote machine.  It also
creates a systemd unit and configures the Blackbox exporter's "modules"
from the `blackbox_modules` Ansible variable.
This commit is contained in:
2022-08-08 21:51:51 -05:00
parent 60505657f3
commit 1e14dd7905
13 changed files with 182 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
- name: ensure /etc/prometheus directory exists
file:
path: /etc/prometheus
mode: u=rwx,go=rx
owner: root
group: root
state: directory
- name: ensure blackbox_exporter is configured
copy:
dest: /etc/prometheus/blackbox.yml
content: |
{{ blackbox_config|to_nice_yaml(indent=2) }}
mode: u=rw,go=r
owner: root
group: root
notify:
- reload blackbox_exporter
- name: ensure blackbox_exporter starts at boot
service:
name: blackbox_exporter
enabled: true
tags:
- service
- name: flush_handlers
meta: flush_handlers
- name: ensure blackbox_exporter is running
service:
name: blackbox_exporter
state: started
tags:
- service

View File

@@ -0,0 +1,55 @@
- name: load installation variables
include_vars: install.yml
tags:
- always
- name: load architecture variables
include_vars: '{{ item }}'
with_first_found:
- '{{ ansible_architecture }}.yml'
- arch-defaults.yml
tags:
- always
- name: ensure blackbox_exporter release archive is available
delegate_to: localhost
become: false
get_url:
url: '{{ blackbox_xptr_tar_url }}'
checksum: 'sha256:{{ blackbox_xptr_cksm_url }}'
dest: '{{ playbook_dir }}/tmp/{{ blackbox_xptr_tar_name }}'
tags:
- download
- name: ensure blackbox_exporter archive is unpacked locally
delegate_to: localhost
become: false
unarchive:
src: '{{ playbook_dir }}/tmp/{{ blackbox_xptr_tar_name }}'
dest: '{{ playbook_dir }}/tmp/'
remote_src: true
creates: '{{ blackbox_xptr_extract_dir }}/blackbox_exporter'
tags:
- unarchive
- name: ensure blackbox_exporter is installed
copy:
src: '{{ blackbox_xptr_extract_dir }}/blackbox_exporter'
dest: /usr/local/sbin/blackbox_exporter
mode: u=rwx,go=rx
diff: false
notify:
- restart blackbox_exporter
- name: ensure blackbox_exporter systemd unit is installed
file:
src: blackbox_exporter.service
dest: /etc/systemd/system/blackbox_exporter.services
mode: u=rw,go=r
notify:
- reload systemd
- restart blackbox_exporter
tags:
- service
- systemd

View File

@@ -0,0 +1,7 @@
- block:
- import_tasks: install.yml
tags:
- install
- import_tasks: deploy.yml
tags:
- blackbox-exporter