Skip to content

Commit 56e752a

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

File tree

9 files changed

+136
-0
lines changed

9 files changed

+136
-0
lines changed

roles/prometheus_install/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Role Name
2+
=========
3+
4+
A brief description of the role goes here.
5+
6+
Requirements
7+
------------
8+
9+
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
10+
11+
Role Variables
12+
--------------
13+
14+
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
15+
16+
Dependencies
17+
------------
18+
19+
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
20+
21+
Example Playbook
22+
----------------
23+
24+
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
25+
26+
- hosts: servers
27+
roles:
28+
- { role: username.rolename, x: 42 }
29+
30+
License
31+
-------
32+
33+
BSD
34+
35+
Author Information
36+
------------------
37+
38+
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
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)