community.grafana.grafana_silence module – Manage Grafana Silences

Note

This module is part of the community.grafana collection (version 1.9.1).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.grafana. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.grafana.grafana_silence.

New in community.grafana 1.8.0

Synopsis

  • Create/delete Grafana Silences through the Alertmanager Silence API.

Requirements

The below requirements are needed on the host that executes this module.

  • The Alertmanager API is only available starting Grafana 8 and the module will fail if the server version is lower than version 8.

Parameters

Parameter

Comments

client_cert

path

PEM formatted certificate chain file to be used for SSL client authentication.

This file can also include the key as well, and if the key is included, client_key is not required

client_key

path

PEM formatted file that contains your private key to be used for SSL client authentication.

If client_cert contains both the certificate and key, this option is not required.

comment

string / required

The comment that describes the silence.

created_by

string / required

The author that creates the silence.

ends_at

string / required

ISO 8601 Timestamp with milliseconds e.g. “2029-07-29T08:45:45.000Z” when the silence will end.

grafana_api_key

string

The Grafana API key.

If set, url_username and url_password will be ignored.

matchers

list / elements=dictionary / required

List of matchers to select which alerts are affected by the silence.

skip_version_check

boolean

Skip Grafana version check and try to reach api endpoint anyway.

This parameter can be useful if you enabled `hide_version` in grafana.ini

Choices:

  • false ← (default)

  • true

starts_at

string / required

ISO 8601 Timestamp with milliseconds e.g. “2029-07-29T08:45:45.000Z” when the silence starts.

state

string

Delete the first occurrence of a silence with the same settings. Can be “absent” or “present”.

Choices:

  • "present" ← (default)

  • "absent"

url

aliases: grafana_url

string / required

The Grafana URL.

url_password

aliases: grafana_password

string

The Grafana password for API authentication.

Default: "admin"

url_username

aliases: grafana_user

string

The Grafana user for API authentication.

Default: "admin"

use_proxy

boolean

If false, it will not use a proxy, even if one is defined in an environment variable on the target hosts.

Choices:

  • false

  • true ← (default)

validate_certs

boolean

If false, SSL certificates will not be validated.

This should only set to false used on personally controlled sites using self-signed certificates.

Choices:

  • false

  • true ← (default)

Examples

---
- name: Create a silence
  community.grafana.grafana_silence:
    grafana_url: "https://grafana.example.com"
    grafana_api_key: "{{ some_api_token_value }}"
    comment: "a testcomment"
    created_by: "me"
    starts_at: "2029-07-29T08:45:45.000Z"
    ends_at: "2029-07-29T08:55:45.000Z"
    matchers:
      - isEqual: true
        isRegex: true
        name: environment
        value: test
    state: present

- name: Delete a silence
  community.grafana.grafana_silence:
    grafana_url: "https://grafana.example.com"
    grafana_api_key: "{{ some_api_token_value }}"
    comment: "a testcomment"
    created_by: "me"
    starts_at: "2029-07-29T08:45:45.000Z"
    ends_at: "2029-07-29T08:55:45.000Z"
    matchers:
      - isEqual: true
        isRegex: true
        name: environment
        value: test
    state: absent

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

silence

complex

Information about the silence

Returned: On success

comment

string

The comment of the silence

Returned: success

Sample: "['this is a test']"

createdBy

string

The author of the silence

Returned: success

Sample: "['me']"

endsAt

string

The end timestamp of the silence

Returned: success

Sample: "['2029-07-29T08:55:45.000Z']"

id

string

The id of the silence

Returned: success

Sample: "['ec27df6b-ac3c-412f-ae0b-6e3e1f41c9c3']"

matchers

list / elements=string

The matchers of the silence

Returned: success

Sample: [[{"isEqual": true, "isRegex": true, "name": "environment", "value": "test"}]]

startsAt

string

The begin timestamp of the silence

Returned: success

Sample: "['2029-07-29T08:45:45.000Z']"

status

dictionary

The status of the silence

Returned: success

Sample: [{"state": "pending"}]

updatedAt

string

The timestamp of the last update for the silence

Returned: success

Sample: "['2023-07-27T13:27:33.042Z']"

Authors

  • flkhndlr (@flkhndlr)