Skip to content

Commit 8eaef2e

Browse files
authored
Update prometheus role for ansible-lint, argument specs, and README (#208)
Signed-off-by: Webster Mudge <wmudge@cloudera.com>
1 parent 71ca915 commit 8eaef2e

File tree

5 files changed

+156
-39
lines changed

5 files changed

+156
-39
lines changed

roles/prometheus/README.md

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,69 @@
1-
<!--
2-
Copyright 2024 Cloudera, Inc.
1+
# prometheus
32

4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
3+
Install Prometheus.
74

8-
https://www.apache.org/licenses/LICENSE-2.0
5+
This role automates the installation of the Prometheus monitoring system from its official distribution archive. It sets up the necessary directories for configuration and the time-series database (TSDB), creates a dedicated system user and group for the service, and installs a basic Prometheus configuration to get started.
96

10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
-->
7+
The role will:
8+
- Create a dedicated system user and group (`prometheus`).
9+
- Create necessary directories for Prometheus configuration (`/etc/prometheus`) and TSDB storage (`/var/lib/prometheus`).
10+
- Download the Prometheus distribution tarball.
11+
- Extract the Prometheus binary and related files to the installation directory.
12+
- Install a basic `prometheus.yml` configuration file.
13+
- Set up a `systemd` service for Prometheus.
14+
- Enable and start the Prometheus service, ensuring it runs on system boot.
1615

17-
# prometheus
16+
# Requirements
17+
18+
- Target host must have `systemd` for service management.
19+
- Internet access on the target host to download the Prometheus tarball.
20+
21+
# Dependencies
22+
23+
None.
24+
25+
# Parameters
26+
27+
| Variable | Type | Required | Default | Description |
28+
| --- | --- | --- | --- | --- |
29+
| `prometheus_tarball_url` | `str` | `False` | `https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz` | URL to the Prometheus distribution archive file. |
30+
| `prometheus_directory` | `path` | `False` | `/etc/prometheus` | Prometheus configuration directory. |
31+
| `prometheus_tsdb_directory` | `path` | `False` | `/var/lib/prometheus` | Prometheus TSDB directory. |
32+
| `prometheus_tarball_file` | `str` | `False` | `prometheus.tar.gz` | Intermediate archive file name for the downloaded tarball. |
33+
| `prometheus_user` | `str` | `False` | `prometheus` | Prometheus service user. |
34+
| `prometheus_group` | `str` | `False` | `prometheus` | Prometheus service group. |
35+
| `prometheus_service_directory` | `path` | `False` | `/etc/systemd/system/prometheus.service` | Prometheus Systemd service directory (full path to the service file). |
36+
37+
# Example Playbook
38+
39+
```yaml
40+
- hosts: monitoring_servers
41+
tasks:
42+
- name: Install Prometheus server with custom settings
43+
ansible.builtin.import_role:
44+
name: prometheus
45+
vars:
46+
prometheus_tarball_url: "[https://github.com/prometheus/prometheus/releases/download/v2.49.0/prometheus-2.49.0.linux-amd64.tar.gz](https://github.com/prometheus/prometheus/releases/download/v2.49.0/prometheus-2.49.0.linux-amd64.tar.gz)"
47+
prometheus_directory: "/opt/prometheus/config"
48+
prometheus_tsdb_directory: "/data/prometheus_tsdb"
49+
prometheus_user: "prom_admin"
50+
prometheus_group: "prom_admin"
51+
```
52+
53+
# License
54+
55+
```
56+
Copyright 2025 Cloudera, Inc.
57+
58+
Licensed under the Apache License, Version 2.0 (the "License");
59+
you may not use this file except in compliance with the License.
60+
You may obtain a copy of the License at
61+
62+
https://www.apache.org/licenses/LICENSE-2.0
63+
64+
Unless required by applicable law or agreed to in writing, software
65+
distributed under the License is distributed on an "AS IS" BASIS,
66+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
67+
See the License for the specific language governing permissions and
68+
limitations under the License.
69+
```

roles/prometheus/defaults/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
---
2-
3-
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
1+
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
64
# you may not use this file except in compliance with the License.
@@ -14,6 +12,8 @@
1412
# See the License for the specific language governing permissions and
1513
# limitations under the License.
1614

15+
---
16+
1717
prometheus_tarball_url: https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz
1818
prometheus_directory: /etc/prometheus
1919
prometheus_tsdb_directory: /var/lib/prometheus

roles/prometheus/handlers/main.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
---
2-
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
1+
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
54
# you may not use this file except in compliance with the License.
@@ -13,7 +12,21 @@
1312
# See the License for the specific language governing permissions and
1413
# limitations under the License.
1514

16-
- name: Restart prometheus
15+
---
16+
17+
- name: Enable Prometheus
18+
block:
19+
- name: Reload systemd daemon
20+
ansible.builtin.systemd:
21+
daemon_reload: true
22+
23+
- name: Enable and start Prometheus service
24+
ansible.builtin.systemd:
25+
name: prometheus
26+
state: started
27+
enabled: true
28+
29+
- name: Restart Prometheus
1730
ansible.builtin.service:
1831
name: prometheus
1932
state: restarted
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2025 Cloudera, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
argument_specs:
16+
main:
17+
short_description: Install Prometheus.
18+
description:
19+
- Install Prometheus from the distribution archive file.
20+
- Set up the local time-series database.
21+
- Set up the service user and group.
22+
- Install a basic configuration.
23+
author: Cloudera Labs
24+
options:
25+
prometheus_tarball_url:
26+
description: URL to the Prometheus distribution archive file.
27+
type: str
28+
required: false
29+
default: https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz
30+
prometheus_directory:
31+
description: Prometheus configuration directory.
32+
type: path
33+
required: false
34+
default: /etc/prometheus
35+
prometheus_tsdb_directory:
36+
description: Prometheus TSDB directory.
37+
type: path
38+
required: false
39+
default: /var/lib/prometheus
40+
prometheus_tarball_file:
41+
description: Intermediate archive file name.
42+
type: str
43+
required: false
44+
default: prometheus.tar.gz
45+
prometheus_user:
46+
description: Prometheus service user.
47+
type: str
48+
required: false
49+
default: prometheus
50+
prometheus_group:
51+
description: Prometheus service group.
52+
type: str
53+
required: false
54+
default: prometheus
55+
prometheus_service_directory:
56+
description: Prometheus Systemd service directory.
57+
type: path
58+
required: false
59+
default: /etc/systemd/system/prometheus.service

roles/prometheus/tasks/main.yml

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
---
2-
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
1+
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
54
# you may not use this file except in compliance with the License.
@@ -13,9 +12,12 @@
1312
# See the License for the specific language governing permissions and
1413
# limitations under the License.
1514

15+
---
16+
1617
- name: Create Prometheus directory
1718
ansible.builtin.file:
1819
path: "{{ prometheus_directory }}"
20+
mode: "0755"
1921
state: directory
2022

2123
- name: Create a temporary directory
@@ -27,15 +29,16 @@
2729
ansible.builtin.get_url:
2830
url: "{{ prometheus_tarball_url }}"
2931
dest: "{{ __prometheus_tmp.path }}/{{ prometheus_tarball_file }}"
32+
mode: "0755"
3033

31-
- name: Extract tarball
34+
- name: Extract Prometheus tarball
3235
ansible.builtin.unarchive:
3336
src: "{{ __prometheus_tmp.path }}/{{ prometheus_tarball_file }}"
3437
dest: "{{ prometheus_directory }}"
3538
extra_opts: --strip-components=1
3639
remote_src: true
3740

38-
- name: Remove the temporary directory
41+
- name: Remove the temporary directory
3942
when: __prometheus_tmp is defined
4043
ansible.builtin.file:
4144
path: "{{ __prometheus_tmp.path }}"
@@ -54,34 +57,24 @@
5457
state: directory
5558
recurse: true
5659

57-
- name: Set ownership of all files inside /etc/prometheus
60+
- name: Set ownership of Prometheus files
5861
ansible.builtin.file:
5962
path: "{{ prometheus_directory }}"
6063
owner: "{{ prometheus_user }}"
6164
group: "{{ prometheus_group }}"
65+
mode: "0755"
6266
recurse: true
6367

6468
- name: Create Prometheus service template
6569
ansible.builtin.template:
6670
src: prometheus.service.j2
6771
dest: "{{ prometheus_service_directory }}"
68-
register: __prometheus_service
69-
70-
- name: Start and enable prometheus service
71-
when: __prometheus_service.changed
72-
block:
73-
- name: Reload systemd daemon
74-
ansible.builtin.systemd:
75-
daemon_reload: true
76-
77-
- name: Enable and start prometheus service
78-
ansible.builtin.systemd:
79-
name: prometheus
80-
state: started
81-
enabled: true
72+
mode: "0755"
73+
notify: Enable Prometheus
8274

8375
- name: Update Prometheus configuration
8476
ansible.builtin.template:
8577
src: prometheus.yml.j2
8678
dest: /etc/prometheus/prometheus.yml
87-
notify: restart prometheus
79+
mode: "0755"
80+
notify: Restart Prometheus

0 commit comments

Comments
 (0)