community.grafana.grafana_datasource 模块 – 管理 Grafana 数据源
注意
此模块是 community.grafana 集合(版本 2.1.0)的一部分。
如果您正在使用 ansible
包,您可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.grafana
。
要在 playbook 中使用它,请指定:community.grafana.grafana_datasource
。
概要
通过 API 创建/更新/删除 Grafana 数据源。
参数
参数 |
注释 |
---|---|
此数据源的访问模式。 选项
|
|
定义的数据用于数据源 jsonData 数据可能会被明确定义的参数(如 zabbix_user)覆盖 默认值: |
|
定义的数据用于数据源 secureJsonData 数据可能会被明确定义的参数(如 tls_client_cert)覆盖 存储为安全数据,请参见 默认值: |
|
当 存储为安全数据,请参见 默认值: |
|
当 默认值: |
|
用于 CloudWatch 数据源类型的 AWS 身份验证类型(grafana api 的 authType) 选项
|
|
当 默认值: |
|
CloudWatch 数据源类型的自定义指标的命名空间 |
|
CloudWatch 数据源类型的 AWS 默认区域 选项
|
|
当 存储为安全数据,请参见 默认值: |
|
用于 Azure AD 应用注册进行身份验证的应用程序/客户端 ID。 |
|
您的 Azure 帐户的国家云 选项
|
|
用于 Azure AD 应用注册进行身份验证的应用程序客户端密钥 |
|
用于 Azure AD 应用注册进行身份验证的目录/租户 ID |
|
当 存储为安全数据,请参见 |
|
数据源基本身份验证用户。 使用 basic_auth_password 设置此选项将启用基本身份验证。 |
|
用于 SSL 客户端身份验证的 PEM 格式证书链文件。 此文件还可以包含密钥,如果包含密钥,则不需要 client_key |
|
包含用于 SSL 客户端身份验证的私钥的 PEM 格式文件。 如果 client_cert 同时包含证书和密钥,则不需要此选项。 |
|
数据源的数据库名称。 当 默认值: |
|
数据源的类型。 当 选项
|
|
数据源的 URL。 当 |
|
默认情况下,安全数据不会更新(请参阅注释!) 要更新安全数据,您必须启用此选项! 启用此选项后,任务将始终报告 changed=True 选项
|
|
Elasticsearch 版本(仅适用于 版本 56 适用于 Elasticsearch 5.6+,您可以在其中指定 选项
|
|
Grafana API 密钥。 如果设置, |
|
对于 Elasticsearch 选项
|
|
将此数据源设置为默认数据源。 选项
|
|
从 Elasticsearch 5.6 开始,您可以指定每个请求的最大并发分片数。 默认值: |
|
数据源的名称。 |
|
应在其中创建数据源的 Grafana 组织 ID。 当设置 与 默认值: |
|
应在其中创建数据源的 Grafana 组织名称。 当设置 与 |
|
数据源密码。 存储为安全数据,请参见 默认值: |
|
选项
|
|
数据源的状态 选项
|
|
Elasticsearch 数据源中时间字段的名称。 例如 默认值: |
|
对于 例如 |
|
用于自签名证书的 TLS CA 证书。 仅当设置 存储为安全数据,请参见 |
|
客户端 TLS 证书。 如果设置 以 —– BEGIN CERTIFICATE —– 开头 存储为安全数据,请参见 |
|
客户端 TLS 私钥 以 —– BEGIN RSA PRIVATE KEY —– 开头 存储为安全数据,请参见 |
|
跳过 TLS 数据源证书验证。 选项
|
|
是否对 Zabbix 数据源类型使用趋势。 选项
|
|
OpenTSDB 时间分辨率。 选项
|
|
OpenTSDB 版本。 对于 <=2.1,使用 选项
|
|
数据源的 uid。 |
|
Grafana URL。 |
|
用于 API 身份验证的 Grafana 密码。 默认值: |
|
用于 API 身份验证的 Grafana 用户名。 默认值: |
|
如果为 选项
|
|
InfluxDB 数据源的数据源登录用户。 默认值: |
|
如果为 此项仅应在个人控制的站点上使用自签名证书时设置为 选项
|
|
是否应将 Cookie 或身份验证标头等凭据与跨站点请求一起发送。 选项
|
|
Zabbix API 的密码 |
|
Zabbix API 的用户 |
Notes(注释)
注意
安全数据将由 Grafana API 加密,因此无法在后续运行中进行比较。为了解决这个问题,安全数据在初始创建后不会更新!要强制更新安全数据,您必须设置enforce_secure_data=True。
提示,由于
enforce_secure_data
始终报告 changed=True,您可以只执行一个更新数据源的任务,而不包含任何安全数据,并创建一个单独的 playbook/任务来更改安全数据。这样就不会破坏任何工作流。
Examples(示例)
---
- name: Create elasticsearch datasource
community.grafana.grafana_datasource:
name: "datasource-elastic"
grafana_url: "https://grafana.org.cnpany.com"
grafana_user: "admin"
grafana_password: "xxxxxx"
org_id: "1"
ds_type: "elasticsearch"
ds_url: "https://elastic.ac.cnmpany.com:9200"
database: "[logstash_]YYYY.MM.DD"
basic_auth_user: "grafana"
basic_auth_password: "******"
time_field: "@timestamp"
time_interval: "1m"
interval: "Daily"
es_version: 56
max_concurrent_shard_requests: 42
tls_ca_cert: "/etc/ssl/certs/ca.pem"
- name: Create influxdb datasource
community.grafana.grafana_datasource:
name: "datasource-influxdb"
grafana_url: "https://grafana.org.cnpany.com"
grafana_user: "admin"
grafana_password: "xxxxxx"
org_id: "1"
ds_type: "influxdb"
ds_url: "https://influx.company.com:8086"
database: "telegraf"
time_interval: ">10s"
tls_ca_cert: "/etc/ssl/certs/ca.pem"
- name: Create influxdbv2 datasource using fluxql
community.grafana.grafana_datasource:
name: "datasource-influxdb-flux"
grafana_url: "https://grafana.org.cnpany.com"
grafana_user: "admin"
grafana_password: "xxxxxx"
org_id: "1"
ds_type: "influxdb"
ds_url: "https://influx.company.com:8086"
additional_json_data:
version: "Flux"
organization: "organization"
defaultBucket: "bucket"
tlsSkipVerify: false
additional_secure_json_data:
token: "token"
- name: Create postgres datasource
community.grafana.grafana_datasource:
name: "datasource-postgres"
grafana_url: "https://grafana.org.cnpany.com"
grafana_user: "admin"
grafana_password: "xxxxxx"
org_id: "1"
ds_type: "postgres"
ds_url: "postgres.company.com:5432"
database: "db"
user: "postgres"
sslmode: "verify-full"
additional_json_data:
postgresVersion: 12
timescaledb: false
additional_secure_json_data:
password: "iampgroot"
- name: Create cloudwatch datasource
community.grafana.grafana_datasource:
name: "datasource-cloudwatch"
grafana_url: "https://grafana.org.cnpany.com"
grafana_user: "admin"
grafana_password: "xxxxxx"
org_id: "1"
ds_type: "cloudwatch"
ds_url: "http://monitoring.us-west-1.amazonaws.com"
aws_auth_type: "keys"
aws_default_region: "us-west-1"
aws_access_key: "speakFriendAndEnter"
aws_secret_key: "mel10n"
aws_custom_metrics_namespaces: "n1,n2"
- name: grafana - add thruk datasource
community.grafana.grafana_datasource:
name: "datasource-thruk"
grafana_url: "https://grafana.org.cnpany.com"
grafana_user: "admin"
grafana_password: "xxxxxx"
org_id: "1"
ds_type: "sni-thruk-datasource"
ds_url: "https://thruk.company.com/sitename/thruk"
basic_auth_user: "thruk-user"
basic_auth_password: "******"
# handle secure data - workflow example
# this will create/update the datasource but dont update the secure data on updates
# so you can assert if all tasks are changed=False
- name: create prometheus datasource
community.grafana.grafana_datasource:
name: openshift_prometheus
ds_type: prometheus
ds_url: https://openshift-monitoring.company.com
access: proxy
tls_skip_verify: true
additional_json_data:
httpHeaderName1: "Authorization"
additional_secure_json_data:
httpHeaderValue1: "Bearer ihavenogroot"
# in a separate task or even play you then can force to update
# and assert if each datasource is reporting changed=True
- name: update prometheus datasource
community.grafana.grafana_datasource:
name: openshift_prometheus
ds_type: prometheus
ds_url: https://openshift-monitoring.company.com
access: proxy
tls_skip_verify: true
additional_json_data:
httpHeaderName1: "Authorization"
additional_secure_json_data:
httpHeaderValue1: "Bearer ihavenogroot"
enforce_secure_data: true
Return Values(返回值)
通用返回值记录在此处,以下是此模块特有的字段
Key(键) |
描述 |
---|---|
模块创建/更新的数据源 Returned: changed(已更改) Sample: |