Skip to content

Commit d5c9c9d

Browse files
authored
Update monitoring roles (#292)
* Add Grafana installation tasks and variables for RedHat and Rocky * Refactor node_exporter service handling to reload and restart in a single task * Add prometheus_scrape_targets option to configure scrape hosts in Prometheus * Refactor Prometheus service management and set SELinux to permissive mode * Update README and argument specs Signed-off-by: rsuplina <[email protected]>
1 parent 507ab24 commit d5c9c9d

File tree

11 files changed

+125
-43
lines changed

11 files changed

+125
-43
lines changed

roles/grafana/tasks/RedHat.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
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+
# http://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+
---
16+
- name: Import Grafana GPG key
17+
ansible.builtin.rpm_key:
18+
state: present
19+
key: "{{ grafana_gpg_key_url }}"
20+
21+
- name: Install Grafana packages
22+
ansible.builtin.yum:
23+
name: "{{ grafana_tarball_url }}"
24+
state: present

roles/grafana/tasks/Rocky.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
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+
# http://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+
---
16+
- name: Import Grafana GPG key
17+
ansible.builtin.rpm_key:
18+
state: present
19+
key: "{{ grafana_gpg_key_url }}"
20+
21+
- name: Install Grafana packages
22+
ansible.builtin.yum:
23+
name: "{{ grafana_tarball_url }}"
24+
state: present

roles/grafana/vars/RedHat.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
3+
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
grafana_tarball_url: https://dl.grafana.com/oss/release/grafana-10.2.3-1.x86_64.rpm
18+
grafana_gpg_key_url: https://rpm.grafana.com/gpg.key
19+
20+
grafana_service: grafana-server

roles/grafana/vars/Rocky.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
3+
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
grafana_tarball_url: https://dl.grafana.com/oss/release/grafana-10.2.3-1.x86_64.rpm
18+
grafana_gpg_key_url: https://rpm.grafana.com/gpg.key
19+
20+
grafana_service: grafana-server

roles/nodeexporter/handlers/main.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313
# limitations under the License.
1414

1515
---
16-
- name: Start node_exporter service
17-
block:
18-
- name: Reload systemd daemon
19-
ansible.builtin.systemd:
20-
daemon_reload: true
21-
22-
- name: Enable and start node_exporter service
23-
ansible.builtin.systemd:
24-
name: node_exporter
25-
state: started
26-
enabled: true
16+
- name: Reload and restart node_exporter
17+
become: true
18+
ansible.builtin.systemd:
19+
name: node_exporter
20+
daemon_reload: true
21+
state: restarted
22+
enabled: true

roles/nodeexporter/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@
5959
src: node_exporter.service.j2
6060
dest: "{{ node_exporter_service_directory }}"
6161
mode: "0755"
62-
notify: Start node_exporter service
62+
notify: Reload and restart node_exporter

roles/prometheus/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The role will:
99
- Create necessary directories for Prometheus configuration (`/etc/prometheus`) and TSDB storage (`/var/lib/prometheus`).
1010
- Download the Prometheus distribution tarball.
1111
- Extract the Prometheus binary and related files to the installation directory.
12+
- Set SELinux to permissive mode on the target host.
1213
- Install a basic `prometheus.yml` configuration file.
1314
- Set up a `systemd` service for Prometheus.
1415
- Enable and start the Prometheus service, ensuring it runs on system boot.
@@ -33,6 +34,7 @@ None.
3334
| `prometheus_user` | `str` | `False` | `prometheus` | Prometheus service user. |
3435
| `prometheus_group` | `str` | `False` | `prometheus` | Prometheus service group. |
3536
| `prometheus_service_directory` | `path` | `False` | `/etc/systemd/system/prometheus.service` | Prometheus Systemd service directory (full path to the service file). |
37+
| `prometheus_scrape_targets` | `list` | `False` | `["localhost"]` | List of hosts to scrape with node_exporter. |
3638

3739
# Example Playbook
3840

roles/prometheus/handlers/main.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,9 @@
1313
# limitations under the License.
1414

1515
---
16-
- name: Enable Prometheus
17-
block:
18-
- name: Reload systemd daemon
19-
ansible.builtin.systemd:
20-
daemon_reload: true
21-
22-
- name: Enable and start Prometheus service
23-
ansible.builtin.systemd:
24-
name: prometheus
25-
state: started
26-
enabled: true
27-
28-
- name: Restart Prometheus
29-
ansible.builtin.service:
16+
- name: Manage Prometheus Service
17+
ansible.builtin.systemd:
3018
name: prometheus
19+
daemon_reload: true
3120
state: restarted
21+
enabled: true

roles/prometheus/meta/argument_specs.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ argument_specs:
1818
short_description: Install Prometheus.
1919
description:
2020
- Install Prometheus from the distribution archive file.
21+
- Set up SELinux to permissive mode (to ensure Prometheus can run without policy restrictions).
2122
- Set up the local time-series database.
2223
- Set up the service user and group.
2324
- Install a basic configuration.
@@ -59,3 +60,10 @@ argument_specs:
5960
type: path
6061
required: false
6162
default: /etc/systemd/system/prometheus.service
63+
prometheus_scrape_targets:
64+
description: List of hosts to scrape with node_exporter
65+
type: list
66+
elements: str
67+
required: false
68+
default:
69+
- "localhost"

roles/prometheus/tasks/main.yml

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

1515
---
16+
- name: Set SELinux to permissive mode
17+
ansible.posix.selinux:
18+
policy: targeted
19+
state: permissive
20+
1621
- name: Create Prometheus directory
1722
ansible.builtin.file:
1823
path: "{{ prometheus_directory }}"
@@ -69,11 +74,11 @@
6974
src: prometheus.service.j2
7075
dest: "{{ prometheus_service_directory }}"
7176
mode: "0755"
72-
notify: Enable Prometheus
77+
notify: Manage Prometheus Service
7378

7479
- name: Update Prometheus configuration
7580
ansible.builtin.template:
7681
src: prometheus.yml.j2
7782
dest: /etc/prometheus/prometheus.yml
7883
mode: "0755"
79-
notify: Restart Prometheus
84+
notify: Manage Prometheus Service

0 commit comments

Comments
 (0)