Skip to content
Open
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
27 changes: 27 additions & 0 deletions roles/prometheus_install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Prometheus Ansible Role

Highly-customizable Ansible role for installing, configuring, and verifying Prometheus on cluster nodes, enabling performance metrics collection.

---

## 🚀 Features

- **Install Prometheus from tarball or latest release**
- **Systemd service management for Prometheus**
- **Modular role design: install, configure, verify**
- **Support for offline and online deployment modes**

---

## 📦 Installation Methods

- **Install from local `.tar.gz` file (offline mode)**
- **Download and install from GitHub release (online mode)**

---

## 📋 Installation

```
$ ansible-playbook -i hosts playbook_prometheus.yml
```
19 changes: 19 additions & 0 deletions roles/prometheus_install/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
galaxy_info:
author: IBM Corporation
description: Role to install Prometheus on cluster node
company: IBM

license: Apache-2.0

min_ansible_version: 2.9

platforms:
- name: EL
versions:
- 8
- 9

galaxy_tags: []

dependencies: []
17 changes: 17 additions & 0 deletions roles/prometheus_install/tasks/configure_prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Create /etc/prometheus directory
file:
path: /etc/prometheus
state: directory
owner: prometheus
group: prometheus
mode: "0755"

- name: Copy prometheus configuration file
copy:
src: "{{ install_dir }}/{{ tarball | regex_replace('.tar.gz','') }}/prometheus.yml"
dest: /etc/prometheus/prometheus.yml
owner: prometheus
group: prometheus
mode: "0644"
remote_src: yes
7 changes: 7 additions & 0 deletions roles/prometheus_install/tasks/create_user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Create Prometheus user
user:
name: prometheus
shell: /sbin/nologin
system: yes
create_home: no
19 changes: 19 additions & 0 deletions roles/prometheus_install/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Ensure Prometheus install directory exists
file:
path: "{{ install_dir }}"
state: directory
mode: "0755"

- name: Download Prometheus tarball
get_url:
url: "{{ download_url }}"
dest: "{{ local_tarball_path }}"
mode: "0644"

- name: Extract Prometheus
unarchive:
src: "{{ local_tarball_path }}"
dest: "{{ install_dir }}"
remote_src: yes
creates: " {{ install_dir }}/prometheus"
12 changes: 12 additions & 0 deletions roles/prometheus_install/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- import_tasks: install.yml
tags: install

- import_tasks: create_user.yml
tags: createuser

- import_tasks: symlink_binaries.yml
tags: symlink

- import_tasks: configure_prometheus.yml
tags: configure
10 changes: 10 additions & 0 deletions roles/prometheus_install/tasks/symlink_binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Symlink Prometheus binaries
file:
src: "{{ install_dir }}/{{ tarball | regex_replace('.tar.gz','') }}/{{ item }}"
dest: "{{ bin_dir }}/{{ item }}"
state: link
force: yes
loop:
- prometheus
- promtool
7 changes: 7 additions & 0 deletions roles/prometheus_install/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: "3.7.0-rc.0"
tarball: "prometheus-{{ version }}.linux-amd64.tar.gz"
download_url: "https://github.com/prometheus/prometheus/releases/download/v{{ version }}/{{ tarball }}"
local_tarball_path: "/tmp/{{ tarball }}"
install_dir: "/opt/prometheus"
bin_dir: "/usr/local/bin"
7 changes: 7 additions & 0 deletions samples/playbook_prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Install and configure Prometheus on cluster
hosts: all
become: true

roles:
- prometheus_install