Skip to content

Commit cc4ac07

Browse files
authored
Add TLS/HTTPS support for Prometheus (#298)
* Add TLS/HTTPS support for Prometheus * Add Prometheus prefix to tls_enabled variable Signed-off-by: rsuplina <[email protected]>
1 parent bd5cd56 commit cc4ac07

File tree

6 files changed

+60
-16
lines changed

6 files changed

+60
-16
lines changed

roles/prometheus/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# prometheus
22

3-
Install Prometheus.
4-
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.
6-
73
The role will:
84
- Create a dedicated system user and group (`prometheus`).
95
- Create necessary directories for Prometheus configuration (`/etc/prometheus`) and TSDB storage (`/var/lib/prometheus`).
@@ -31,6 +27,10 @@ None.
3127
| `prometheus_directory` | `path` | `False` | `/etc/prometheus` | Prometheus configuration directory. |
3228
| `prometheus_tsdb_directory` | `path` | `False` | `/var/lib/prometheus` | Prometheus TSDB directory. |
3329
| `prometheus_tarball_file` | `str` | `False` | `prometheus.tar.gz` | Intermediate archive file name for the downloaded tarball. |
30+
| `prometheus_tls_enabled` | `bool` | `False` | `false` | Enable or disable TLS/SSL for Prometheus (HTTPS support). |
31+
| `prometheus_tls_cert_path` | `str` | `False` | `/etc/pki/tls/certs/prometheus.crt` | Path to the TLS certificate file for Prometheus. |
32+
| `prometheus_tls_key_path` | `str` | `False` | `/etc/pki/tls/private/prometheus.key` | Path to the TLS private key file for Prometheus. |
33+
| `prometheus_web_config_file` | `str` | `False` | `/etc/prometheus/web.yml` | Path to the Prometheus web config file (for TLS settings). |
3434
| `prometheus_user` | `str` | `False` | `prometheus` | Prometheus service user. |
3535
| `prometheus_group` | `str` | `False` | `prometheus` | Prometheus service group. |
3636
| `prometheus_service_directory` | `path` | `False` | `/etc/systemd/system/prometheus.service` | Prometheus Systemd service directory (full path to the service file). |
@@ -48,8 +48,8 @@ None.
4848
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)"
4949
prometheus_directory: "/opt/prometheus/config"
5050
prometheus_tsdb_directory: "/data/prometheus_tsdb"
51-
prometheus_user: "prom_admin"
52-
prometheus_group: "prom_admin"
51+
prometheus_user: "prometheus"
52+
prometheus_group: "prometheus"
5353
```
5454
5555
# License

roles/prometheus/defaults/main.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
# limitations under the License.
1414

1515
---
16-
1716
prometheus_tarball_url: https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz
1817
prometheus_directory: /etc/prometheus
1918
prometheus_tsdb_directory: /var/lib/prometheus
2019
prometheus_tarball_file: prometheus.tar.gz
2120

22-
prometheus_user: prometheus
23-
prometheus_group: prometheus
21+
prometheus_tls_enabled: false
22+
prometheus_tls_cert_path: /etc/pki/tls/certs/prometheus.crt
23+
prometheus_tls_key_path: /etc/pki/tls/private/prometheus.key
24+
prometheus_web_config_file: /etc/prometheus/web.yml
2425

2526
prometheus_service_directory: /etc/systemd/system/prometheus.service
27+
prometheus_user: prometheus
28+
prometheus_group: prometheus

roles/prometheus/meta/argument_specs.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,42 @@
1515

1616
argument_specs:
1717
main:
18-
short_description: Install Prometheus.
18+
short_description: Install, configure, and provision Prometheus server with optional TLS/HTTPS support
1919
description:
20-
- Install Prometheus from the distribution archive file.
21-
- Set up SELinux to permissive mode (to ensure Prometheus can run without policy restrictions).
22-
- Set up the local time-series database.
23-
- Set up the service user and group.
24-
- Install a basic configuration.
20+
- Create a dedicated system user and group for Prometheus.
21+
- Create necessary directories for Prometheus configuration and TSDB storage.
22+
- Download the Prometheus distribution tarball from the official source.
23+
- Extract the Prometheus binary and related files to the installation directory.
24+
- Set SELinux to permissive mode on the target host.
25+
- Install a basic prometheus.yml configuration file.
26+
- Set up a systemd service for Prometheus.
27+
- Enable and start the Prometheus service, ensuring it runs on system boot.
28+
- Optionally enable TLS/HTTPS support for secure endpoints.
29+
- Optionally configure a Prometheus web config file for TLS settings.
30+
- Allow flexible configuration of scrape targets and storage locations via variables.
2531
author: Cloudera Labs
2632
version_added: "2.4.0"
2733
options:
34+
prometheus_tls_enabled:
35+
description: Enable or disable TLS/SSL for Prometheus (HTTPS support).
36+
type: bool
37+
required: false
38+
default: false
39+
prometheus_tls_cert_path:
40+
description: Path to the TLS certificate file for Prometheus.
41+
type: str
42+
required: false
43+
default: /etc/pki/tls/certs/prometheus.crt
44+
prometheus_tls_key_path:
45+
description: Path to the TLS private key file for Prometheus.
46+
type: str
47+
required: false
48+
default: /etc/pki/tls/private/prometheus.key
49+
prometheus_web_config_file:
50+
description: Path to the Prometheus web config file (for TLS settings).
51+
type: str
52+
required: false
53+
default: /etc/prometheus/web.yml
2854
prometheus_tarball_url:
2955
description: URL to the Prometheus distribution archive file.
3056
type: str

roles/prometheus/tasks/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@
6969
mode: "0755"
7070
recurse: true
7171

72+
- name: Render Prometheus web.yml for TLS
73+
when: prometheus_tls_enabled | bool
74+
ansible.builtin.template:
75+
src: web.yml.j2
76+
dest: "{{ prometheus_web_config_file }}"
77+
owner: "{{ prometheus_user }}"
78+
group: "{{ prometheus_group }}"
79+
mode: "0644"
80+
7281
- name: Create Prometheus service template
7382
ansible.builtin.template:
7483
src: prometheus.service.j2

roles/prometheus/templates/prometheus.service.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ ExecStart={{ prometheus_directory }}/prometheus \
1010
--config.file {{ prometheus_directory }}/prometheus.yml \
1111
--storage.tsdb.path {{ prometheus_tsdb_directory }}/ \
1212
--web.console.templates={{ prometheus_directory }}/consoles \
13-
--web.console.libraries={{ prometheus_directory }}/console_libraries
13+
--web.console.libraries={{ prometheus_directory }}/console_libraries \
14+
{% if prometheus_tls_enabled | bool %}--web.config.file={{ prometheus_web_config_file }}{% endif %}
15+
1416
[Install]
1517
WantedBy=multi-user.target
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
tls_server_config:
3+
cert_file: {{ prometheus_tls_cert_path }}
4+
key_file: {{ prometheus_tls_key_path }}

0 commit comments

Comments
 (0)