ansible-collections / community.grafana

Grafana Collection for Ansible
http://galaxy.ansible.com/community/grafana
GNU General Public License v3.0
131 stars 83 forks source link

Create Grafana 'add annotation' module #141

Open aorfanos opened 3 years ago

aorfanos commented 3 years ago
SUMMARY

Add a single annotation to Grafana via Ansible, with dynamic variables (e.g. endpoint, dashboard_id's).

ISSUE TYPE
COMPONENT NAME

community.grafana.add_grafana_annotation

ADDITIONAL INFORMATION

I wanted to utilise Grafana annotations for my Ansible deployments, but the callback plugin seemed too limited for my use-case (different Grafana endpoints - various projects/environments and single Ansible repo, different dashboards to be updated by each role etc, which I believe is a common setup for many people).

An 'add annotation' module is more useful for that kind of operation, because it can utilise group_vars or defaults to achieve the desired result.

I have created a sample module at my GitHub, let me know if it needs anything else to be included in community.grafana.

- name: Create a Grafana annotation
  add_grafana_annotation:
    grafana_api_url: "https://grafana.myproject.com"
    grafana_api_key: "..."
    dashboard_id: 468
    panel_id: 20
    text: "Annotation description"
    tags:
      - tag1
      - tag2
rrey commented 3 years ago

@aorfanos I used to have a module to do that but I’m not sure it is still working : https://github.com/rrey/ansible-module-grafana-annotations It could be a good reason to add it in the collection and maintain it !

aorfanos commented 3 years ago

Another small note on that: In my module I implemented 'annotate dashboard by name' functionality, so if we could have the same in the community module it would be amazing :)

Example usage:

- name: Create a Grafana annotation
  add_grafana_annotation:
    grafana_api_url: "https://grafana.myproject.com"
    grafana_api_key: "..."
    dashboard_name: "AlertManager Overview"
    panel_id: 1
    text: "Annotation description"
    tags:
      - tag1