Grafana Install

This role installs and configures Grafana on RedHat-based systems.

Overview

This role installs and configures Grafana on RedHat-based systems. It adds the official Grafana repository, installs the Grafana package, configures HTTPS with SSL certificates, configures SQLite in WAL mode to avoid database lock errors, sets up SMTP for email alerts via Gmail, deploys Synology SNMP MIB files, and enables the grafana-server service to start on boot.

What This Role Does

  1. Adds Grafana YUM repository

  2. Installs Grafana package via dnf/yum

    • Latest stable version from official repository
  3. Enables and starts grafana-server service

    • Starts grafana-server
    • Service starts on boot automatically
  4. Configures server settings in /etc/grafana/grafana.ini:

    • Protocol (HTTP or HTTPS)
    • Bind address (IP)
    • SSL certificate paths (if HTTPS)
    • SQLite WAL mode and retry settings (avoids database lock errors)
    • Creates backup of config file before changes
  5. Configures SMTP settings for email alerts:

    • Gmail SMTP server
    • Authentication credentials
    • From address and name
    • StartTLS encryption
  6. Creates SNMP MIB directory (/usr/share/snmp/mibs/)

  7. Copies Synology MIB files for SNMP monitoring

  8. Restarts grafana-server if configuration changed (via handler)

Role Variables

VariableDescription
grafana_install_protocolWeb interface protocol (http or https)
grafana_install_http_addrIP address to bind
grafana_install_cert_fileSSL certificate path
grafana_install_cert_keySSL private key path
grafana_install_wal_enabledEnable SQLite WAL mode (avoids database lock errors on alerts)
grafana_install_query_retriesQuery retries on SQLite lock
grafana_install_transaction_retriesTransaction retries on SQLite lock
grafana_install_smtp_enabledEnable SMTP email alerts
grafana_install_smtp_hostSMTP server and port
grafana_install_smtp_userSMTP username (Gmail address)
grafana_install_smtp_passwordSMTP app password
grafana_install_smtp_from_addressFrom address
grafana_install_smtp_from_nameFrom name
grafana_install_smtp_starttls_policyStartTLS policy for SMTP
grafana_install_mibs_dest_dirSNMP MIB files directory

Notes

  • Run deploy_ssl_certificates before this role to ensure cert files exist
  • SQLite WAL mode is enabled by default — fixes “database is locked” errors when Grafana handles concurrent alert evaluations
  • SMTP credentials are stored in Ansible Vault
  • Gmail requires an App Password (not account password) for SMTP with 2FA enabled
  • Synology MIB files are deployed to enable SNMP-based NAS monitoring in dashboards