0x0i.grafana
Ansible Role: 🌈 📊 Grafana
Table of Contents
- Supported Platforms
- Requirements
- Role Variables
- Dependencies
- Example Playbook
- License
- Author Information
This Ansible role installs and configures Grafana, a platform for analytics and monitoring.
Supported Platforms:
* Debian
* Redhat (CentOS/Fedora)
* Ubuntu
Requirements
You need to have the unzip/gtar
tool installed on the target host. For more details, check the Ansible unarchive
module notes. Also, make sure you have Grafana version 5.0 or higher.
Role Variables
The role variables are categorized into these stages:
- install
- config
- launch
- uninstall
Install
grafana
can be installed using compressed files (.tar, .zip) or DEB and RPM packages, obtained from different sources.
The following variables can be changed to customize the installation process:
grafana_user: <service-user-name>
(default: grafana)
grafana_group: <service-group-name>
(default: grafana)
- This is the service user and group used by
grafana
for better security.
install_type: <package | archive>
(default: archive)
package: For Debian and Redhat distributions, it gets the specified package from the package management repository.
- Note: The installation path is determined by the package system and defaults to
/usr/{sbin,lib, share}
.
- Note: The installation path is determined by the package system and defaults to
archive: It can use both tar and zip formats. You can get the installation files from local and remote compressed archives.
install_dir: </path/to/installation/dir>
(default: /opt/grafana
)
- Path on the target host where the
grafana
files will be saved.
archive_url: <path-or-url-to-archive>
(default: see defaults/main.yml
)
- Link to a compressed tar or zip file with
grafana
files. You can find links to official versions here.
archive_checksum: <path-or-url-to-checksum>
(default: see defaults/main.yml
)
- Link to a checksum file for checking the integrity of the
grafana
archive. It's a good practice to use it but it's not required.
package_url: <path-or-url-to-package>
(default: see defaults/main.yml
)
- Link to a debian (DEB) or RPM package with
grafana
files. You can find links to official versions here.
Config
With this role, you can customize your grafana
installation using these components:
- Grafana service settings (
grafana.ini
) - Data source setups (
provisioning/datasources - *.[json|yml]
) - Dashboard setups (
provisioning/dashboards - *.[json|yml]
) - Notifications (
provisioning/notifiers - [json|yml]
)
Here are some configuration variables you can adjust:
config_dir: </path/to/configuration/dir>
(default: {{ install_dir }}
)
- Path on the target host for the
grafana
config file.
provision_configs: <['datasources', 'dashboards' and/or 'notifiers']>
(default: [])
- List of Grafana components to configure.
Grafana Service Configuration
The Grafana service settings are found in an INI file called grafana.ini
. This file organizes different settings of the Grafana service.
You can define sections within the grafana_config
hash, using key-value pairs for settings.
Example:
grafana_config:
paths:
data: /mnt/data/grafana
logs: /mnt/logs/grafana
And others like:
server:
http_addr: 127.0.0.1
http_port: 3030
You can customize many sections related to the server, database, security, users, alerting, plugins, and more.
Launch
This role can start the grafana
web server using the systemd tool.
You can adjust these variables to manage how the service is started:
extra_run_args: <grafana-cli-options>
(default: []
)
- Additional arguments for the
grafana
command when launched.
custom_unit_properties: <hash-of-systemd-service-settings>
(default: []
)
- Custom settings for the [Service] unit configuration and environment of the Grafana systemd service.
Uninstall
You can remove Grafana and its files, returning the host to its previous state.
You can customize this uninstall process with:
perform_uninstall: <true | false>
(default: false
)
- Set this to
true
to uninstall and delete everything related tografana
.
Dependencies
- 0x0i.systemd
Example Playbook
For a default installation:
- hosts: all
roles:
- role: 0x0I.grafana
To install a specific version of Grafana:
- hosts: all
roles:
- role: 0x0I.grafana
vars:
archive_url: https://dl.grafana.com/oss/release/grafana-6.6.1.linux-amd64.tar.gz
archive_checksum: 0edc8207e356ef66eb7b1c78a1cdabc2cd5c0655de774000de2ad0397e543377
To adjust installation paths:
- hosts: all
roles:
- role: 0x0I.grafana
vars:
install_dir: /usr/local
config_dir: /etc/grafana
data_dir: /mnt/grafana
To launch Grafana in debug mode:
- hosts: all
roles:
- role: 0x0I.grafana
vars:
grafana_config:
log:
level: debug
mode: console
License
MIT
Author Information
This role was created in 2019 by O1.IO.
Grafana - an analytics and monitoring observability platform
ansible-galaxy install 0x0i.grafana