Skip to content

Commit 057508d

Browse files
Ansible role 'prometheus_install' for installing prometheus
Signed-off-by: CODING-Enthusiast9857 <madhavison06@gmail.com>
1 parent 1734473 commit 057508d

File tree

9 files changed

+125
-0
lines changed

9 files changed

+125
-0
lines changed

roles/prometheus_install/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Prometheus Ansible Role
2+
3+
Highly-customizable Ansible role for installing, configuring, and verifying Prometheus on cluster nodes, enabling performance metrics collection.
4+
5+
---
6+
7+
## 🚀 Features
8+
9+
- **Install Prometheus from tarball or latest release**
10+
- **Systemd service management for Prometheus**
11+
- **Modular role design: install, configure, verify**
12+
- **Support for offline and online deployment modes**
13+
14+
---
15+
16+
## 📦 Installation Methods
17+
18+
- **Install from local `.tar.gz` file (offline mode)**
19+
- **Download and install from GitHub release (online mode)**
20+
21+
---
22+
23+
## 📋 Installation
24+
25+
```
26+
$ ansible-playbook -i hosts playbook_prometheus.yml
27+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
galaxy_info:
3+
author: IBM Corporation
4+
description: Role to install Prometheus on cluster node
5+
company: IBM
6+
7+
license: Apache-2.0
8+
9+
min_ansible_version: 2.9
10+
11+
platforms:
12+
- name: EL
13+
versions:
14+
- 8
15+
- 9
16+
17+
galaxy_tags: []
18+
19+
dependencies: []
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
- name: Create /etc/prometheus directory
3+
file:
4+
path: /etc/prometheus
5+
state: directory
6+
owner: prometheus
7+
group: prometheus
8+
mode: "0755"
9+
10+
- name: Copy prometheus configuration file
11+
copy:
12+
src: "{{ prometheus_install_dir }}/{{ prometheus_tarball | regex_replace('.tar.gz','') }}/prometheus.yml"
13+
dest: /etc/prometheus/prometheus.yml
14+
owner: prometheus
15+
group: prometheus
16+
mode: "0644"
17+
remote_src: yes
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: Create Prometheus user
3+
user:
4+
name: prometheus
5+
shell: /sbin/nologin
6+
system: yes
7+
create_home: no
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
- name: Ensure Prometheus install directory exists
3+
file:
4+
path: "{{ prometheus_install_dir }}"
5+
state: directory
6+
mode: "0755"
7+
8+
- name: Download Prometheus tarball
9+
get_url:
10+
url: "{{ prometheus_download_url }}"
11+
dest: "{{ prometheus_local_tarball_path }}"
12+
mode: "0644"
13+
14+
- name: Extract Prometheus
15+
unarchive:
16+
src: "{{ prometheus_local_tarball_path }}"
17+
dest: "{{ prometheus_install_dir }}"
18+
remote_src: yes
19+
creates: " {{ prometheus_install_dir }}/prometheus"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
- import_tasks: install.yml
3+
tags: install
4+
5+
- import_tasks: create_user.yml
6+
tags: createuser
7+
8+
- import_tasks: symlink_binaries.yml
9+
tags: symlink
10+
11+
- import_tasks: configure_prometheus.yml
12+
tags: configure
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Symlink Prometheus binaries
3+
file:
4+
src: "{{ prometheus_install_dir }}/{{ prometheus_tarball | regex_replace('.tar.gz','') }}/{{ item }}"
5+
dest: "{{ prometheus_bin_dir }}/{{ item }}"
6+
state: link
7+
force: yes
8+
loop:
9+
- prometheus
10+
- promtool
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
prometheus_version: "3.7.0-rc.0"
3+
prometheus_tarball: "prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
4+
prometheus_download_url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/{{ prometheus_tarball }}"
5+
prometheus_local_tarball_path: "/tmp/{{ prometheus_tarball }}"
6+
prometheus_install_dir: "/opt/prometheus"
7+
prometheus_bin_dir: "/usr/local/bin"

samples/playbook_prometheus.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: Install and configure Prometheus on cluster
3+
hosts: all
4+
become: true
5+
6+
roles:
7+
- prometheus_install

0 commit comments

Comments
 (0)