Grafana Datasource Create

This role creates InfluxDB datasources in Grafana using the API.

Overview

This role creates InfluxDB datasources in Grafana using the Grafana HTTP API. It authenticates with an API token, configures datasources with InfluxQL query language support, and implements idempotent creation that safely handles existing datasources without errors.

What This Role Does

  1. Sends POST request to Grafana API (/api/datasources)
  2. Authenticates with Bearer token (API key)
  3. Configures datasource with parameters:
    • Type: influxdb
    • Access mode: proxy (requests proxied through Grafana backend)
    • URL: InfluxDB server address
    • Database name
    • Authentication credentials
    • Query language: InfluxQL
    • HTTP method: GET
  4. Handles existing datasources gracefully (status 409 = already exists)
  5. Repeats for each datasource in the list

Role Variables

VariableDescription
vault_grafana_ansibleuser_api_tokenGrafana API token (from vault)
grafana_datasource_create_datasourcesList of datasource configurations
grafana_datasource_create_hostGrafana server host:port
grafana_datasource_create_portGrafana HTTP port
grafana_datasource_create_validate_certsValidate SSL certificates

Datasource definition fields:

FieldDescription
nameDisplay name in Grafana UI
uidUnique identifier for dashboard references
urlInfluxDB HTTP API URL
databaseInfluxDB database name
userInfluxDB username
passwordInfluxDB password (from vault)
is_defaultMake this the default datasource

Notes

  • Uses Bearer token authentication (not basic auth)
  • Currently supports InfluxDB datasources with InfluxQL query language
  • Run grafana_install and influxdb roles before this role