Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 66 additions & 13 deletions roles/grafana/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,70 @@
<!--
Copyright 2024 Cloudera, Inc.
# grafana_server

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Set up Grafana server, connected to a Prometheus server.

https://www.apache.org/licenses/LICENSE-2.0
The role will:
- Install the Grafana server package(s).
- Configure Grafana data sources, primarily for Prometheus, based on the provided `prometheus_url`.
- Configure Grafana dashboard providers.
- Provision a default dashboard.

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
## Requirements

# grafana
- A running Prometheus server accessible from the Grafana host.

## Dependencies

None.

## Role Variables (Argument Specification)

| Parameter | Type | Default Value | Description |
|----------------------------------|------|-------------------------------------------------|---------------------------------------------------------------------------|
| `grafana_datasource_directory` | `str`| `/etc/grafana/provisioning/datasources/automatic.yml`| Location of the Grafana data sources configuration file. |
| `grafana_providers_configuration`| `str`| `/etc/grafana/provisioning/dashboards/providers.yml` | Location of the Grafana dashboard provider configurations file. |
| `grafana_dashboard_directory` | `str`| `/var/lib/grafana/dashboards` | Location of the Grafana dashboard configurations directory. |
| `prometheus_url` | `str`| `localhost:9090` | URL (host:port) to the Prometheus server that Grafana will connect to. |

## Examples

Basic installation connecting to a local Prometheus server:

```yaml
- name: Set up Grafana server with local Prometheus
ansible.builtin.import_role:
name: grafana_server
# No variables needed here as defaults will be used for local Prometheus

- name: Set up Grafana server for a specific Prometheus endpoint
ansible.builtin.import_role:
name: grafana_server
vars:
prometheus_url: "http://my-prometheus-server.example.com:9090"

- name: Set up Grafana with custom provisioning directories
ansible.builtin.import_role:
name: grafana_server
vars:
grafana_datasource_directory: "/opt/grafana/configs/datasources.yml"
grafana_providers_configuration: "/opt/grafana/configs/providers.yml"
grafana_dashboard_directory: "/opt/grafana/dashboards_custom"
prometheus_url: "http://monitoring-cluster.internal:9090"
```

## License

```
Copyright 2025 Cloudera, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
4 changes: 2 additions & 2 deletions roles/grafana/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
---

# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

---

grafana_datasource_directory: /etc/grafana/provisioning/datasources/automatic.yml
grafana_providers_configuration: /etc/grafana/provisioning/dashboards/providers.yml
grafana_dashboard_directory: /var/lib/grafana/dashboards
Expand Down
41 changes: 41 additions & 0 deletions roles/grafana/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2025 Cloudera, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

argument_specs:
main:
short_description: Set up Grafana server
description: |
Set up Grafana server, connected to a Prometheus server.
author: Cloudera Labs
options:
grafana_datasource_directory:
description:
- Location of the Grafana data sources.
type: str
default: /etc/grafana/provisioning/datasources/automatic.yml
grafana_providers_configuration:
description:
- Location of the Grafana provider configurations.
type: str
default: /etc/grafana/provisioning/dashboards/providers.yml
grafana_dashboard_directory:
description:
- Locattion of the Grafana dashboard configurations.
type: str
default: /var/lib/grafana/dashboards
prometheus_url:
description:
- URL (host:port) to the Prometheus server.
type: str
default: localhost:9090
25 changes: 25 additions & 0 deletions roles/grafana/tasks/CentOS.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---

- name: Import Grafana GPG key
ansible.builtin.rpm_key:
state: present
key: "{{ grafana_gpg_key_url }}"

- name: Install Grafana packages
ansible.builtin.yum:
name: "{{ grafana_tarball_url }}"
state: present
52 changes: 0 additions & 52 deletions roles/grafana/tasks/Grafana-CentOS.yml

This file was deleted.

50 changes: 0 additions & 50 deletions roles/grafana/tasks/Grafana-Ubuntu.yml

This file was deleted.

23 changes: 23 additions & 0 deletions roles/grafana/tasks/Ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---

- name: Update APT package cache
ansible.builtin.apt:
update_cache: true

- name: Install Grafana packages
ansible.builtin.apt:
deb: "{{ grafana_deb_url }}"
40 changes: 37 additions & 3 deletions roles/grafana/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,5 +11,40 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Include distribution specific tasks
ansible.builtin.include_tasks: "Grafana-{{ ansible_facts['distribution'] }}.yml"

---

- name: Load OS-specific Grafana variables
ansible.builtin.include_vars: "{{ ansible_facts['distribution'] }}.yml"

- name: Execute OS-specific Grafana installation
ansible.builtin.include_tasks: "{{ ansible_facts['distribution'] }}.yml"

- name: Connect Prometheus datasource
ansible.builtin.template:
src: prometheus_source.yml.j2
dest: "{{ grafana_datasource_directory }}"
mode: "0755"

- name: Add configuration for reading dashboards
ansible.builtin.template:
src: providers.yml.j2
dest: "{{ grafana_providers_configuration }}"
mode: "0755"

- name: Ensure that directory for dashboards exist
ansible.builtin.file:
path: "{{ grafana_dashboard_directory }}"
mode: "0755"
state: directory

- name: Copy default node exporter dashboard
ansible.builtin.copy:
src: files/base_dashboard.json
dest: "{{ grafana_dashboard_directory }}/base_dashboard.json"
mode: "0755"

- name: Start Grafana service
ansible.builtin.systemd:
name: "{{ grafana_service }}"
state: started
4 changes: 3 additions & 1 deletion roles/grafana/vars/CentOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
# limitations under the License.

grafana_tarball_url: https://dl.grafana.com/oss/release/grafana-10.2.3-1.x86_64.rpm
gpg_key_url: https://rpm.grafana.com/gpg.key
grafana_gpg_key_url: https://rpm.grafana.com/gpg.key

grafana_service: grafana-server
2 changes: 2 additions & 0 deletions roles/grafana/vars/Ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@

grafana_deb_url: https://dl.grafana.com/oss/release/grafana_10.2.3_amd64.deb
grafana_deb_file: grafana.deb

grafana_service: grafana-server
Loading