Skip to content

Commit

Permalink
Add role to install the Blackbox exporter for Prometheus (cloudera-la…
Browse files Browse the repository at this point in the history
…bs#178)

Signed-off-by: rsuplina <[email protected]>
  • Loading branch information
rsuplina authored Mar 4, 2024
1 parent 6bdc8aa commit 067126d
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
26 changes: 26 additions & 0 deletions roles/blackbox/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---

# 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
88 changes: 88 additions & 0 deletions roles/blackbox/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---

# 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 }}"
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 }}"

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

- 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 /etc/blackbox
ansible.builtin.file:
path: "{{ blackbox_directory }}"
owner: "{{ blackbox_user }}"
group: "{{ blackbox_group }}"
recurse: yes

- name: Copy blackbox binary to /usr/local/bin
ansible.builtin.copy:
remote_src: yes
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 }}"
register: __blackbox_service

- name: Start and enable Blackbox service
when: __blackbox_service.changed
block:

- name: Reload systemd daemon
ansible.builtin.systemd:
daemon_reload: yes

- name: Start Blackbox service
ansible.builtin.systemd:
name: blackbox
state: started
enabled: yes
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

0 comments on commit 067126d

Please sign in to comment.