Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

feat: grafana_organization module and simplify vars-structure #17

Merged
merged 21 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 26 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
# Ansible Grafana

![telekom-mms/ansible-role-grafana](https://github.com/telekom-mms/ansible-role-grafana/workflows/test/badge.svg)
[![Ansible Role](https://img.shields.io/ansible/role/d/57215)](https://galaxy.ansible.com/telekom_mms/grafana)
[![Ansible Role](https://img.shields.io/ansible/role/d/32178)](https://galaxy.ansible.com/ui/standalone/roles/telekom-mms/grafana/)

Configure Grafana dashboards, folders, datasources, teams and users.
Configure Grafana organizations, dashboards, folders, datasources, teams and users.

## Dependencies

collections:
community.grafana
### Collections
- community.grafana

## Role Variables

| Variable | Required | Default |
| -------- | -------- | ------- |

| **grafana**
| url | yes |
| url_username | yes |
| url_password | yes |
| **grafana_users**
| grafana_url | yes |
| grafana_username | yes |
| grafana_password | yes |
| [**grafana_users**](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_user_module.html)
| name | yes |
| email | no |
| login | yes |
| password | no |
| is_admin | no |
| state | no |
| **grafana_teams**
| [**grafana_organizations**](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_organization_module.html)
| name | yes |
| state | no |
| [**grafana_teams**](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_team_module.html)
| name | yes |
| email | no |
| members | no |
| state | no |
| enforce_members | no |
| skip_version_check | no |
| **grafana_datasources**
| [**grafana_datasources**](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_datasource_module.html)
| tls_skip_verify | no |
| org_id | no |
| name | yes |
Expand All @@ -47,11 +48,11 @@ community.grafana
| password | no |
| additional_json_data | no |
| additional_secure_json_data | no |
| **grafana_folders**
| [**grafana_folders**](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_folder_module.html)
| name | yes |
| state | no |
| skip_version_check | no |
| **grafana_dashboards**
| [**grafana_dashboards**](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_dashboard_module.html)
| org_id | no |
| folder | no |
| state | no |
Expand All @@ -65,28 +66,25 @@ community.grafana

## Example Playbook

```bash
```yaml
---
- hosts: localhost
gather_facts: false
collections:
- community.grafana
roles:
- role: grafana

vars:
grafana_url: "{{ icinga_url }}/grafanaweb"
grafana_username: "{{ icinga_user }}"
grafana_password: "{{ icinga_pass }}"
grafana_url: "https://monitoring.example.com"
grafana_username: "api-user"
grafana_password: "******"

grafana_datasources:
- datasource_object:
- loki
name: "Loki"
- name: "Loki"
ds_type: "loki"
ds_url: "http://127.0.0.1:3100"
tls_skip_verify: yes
grafana_folders:
- folder_object:
- my_service
- other_service
- name: my_service
- name: other_service

roles:
- role: telekom-mms.grafana
```
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
grafana_organizations: []
grafana_users: []
grafana_teams: []
grafana_datasources: []
Expand Down
26 changes: 7 additions & 19 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@ galaxy_info:
author: telekom_mms
description: Configure Grafana dashboards, folders, datasources, teams and users
license: GPLv3
min_ansible_version: 2.9
galaxy_tags:
- grafana
- monitoring
min_ansible_version: "2.9"
galaxy_tags: [grafana, monitoring]
platforms:
- name: EL
versions:
- all
- name: Fedora
versions:
- all
- name: Amazon
versions:
- all
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all
- {name: EL, versions: [all]}
- {name: Fedora, versions: [all]}
- {name: Amazon, versions: [all]}
- {name: Debian, versions: [all]}
- {name: Ubuntu, versions: [all]}
14 changes: 4 additions & 10 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,15 @@
grafana_password: admin

grafana_datasources:
- datasource_object:
- loki
name: Loki
- name: Loki
ds_type: loki
ds_url: http://127.0.0.1:3100
tls_skip_verify: true

grafana_folders:
- folder_object:
- my_service
- other_service
- name: my_service
- name: other_service

grafana_dashboards:
- dashboard_object:
- dashboard
folder: my_service
dashboard_uid: ES5apb27k
- folder: my_service
path: test_dashboard.json
5 changes: 2 additions & 3 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
collections:
- name: community.grafana
version: 1.5.4
---
collections: [{name: community.grafana, version: 1.5.4}]
107 changes: 56 additions & 51 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,95 @@
---
- name: Manage organization
community.grafana.grafana_organization:
url: "{{ grafana_url }}"
url_username: "{{ grafana_username }}"
url_password: "{{ grafana_password }}"
name: "{{ organization.name }}"
state: "{{ organization.state | default(omit) }}"
loop: "{{ grafana_organizations }}"
loop_control: {loop_var: organization}
tags: organization

# datasource.0 = grafana_datasource attribute
- name: Manage datasource
community.grafana.grafana_datasource:
url: "{{ grafana_url }}"
url_username: "{{ grafana_username }}"
url_password: "{{ grafana_password }}"
tls_skip_verify: "{{ datasource.0.tls_skip_verify | default(omit) }}"
org_id: "{{ datasource.0.org_id | default(omit) }}"
name: "{{ datasource.0.name }}"
ds_type: "{{ datasource.0.ds_type | default(omit) }}"
access: "{{ datasource.0.access | default(omit) }}"
ds_url: "{{ datasource.0.ds_url | default(omit) }}"
database: "{{ datasource.0.database | default(omit) }}"
with_credentials: "{{ datasource.0.with_credentials | default(omit) }}"
is_default: "{{ datasource.0.is_default | default(omit) }}"
user: "{{ datasource.0.user | default(omit) }}"
password: "{{ datasource.0.password | default(omit) }}"
additional_json_data: "{{ datasource.0.additional_json_data | default(omit) }}"
additional_secure_json_data: "{{ datasource.0.additional_secure_json_data | default(omit) }}"
loop: "{{ grafana_datasources | subelements('datasource_object') }}"
loop_control:
loop_var: datasource
tls_skip_verify: "{{ datasource.tls_skip_verify | default(omit) }}"
org_id: "{{ datasource.org_id | default(omit) }}"
name: "{{ datasource.name }}"
ds_type: "{{ datasource.ds_type | default(omit) }}"
access: "{{ datasource.access | default(omit) }}"
ds_url: "{{ datasource.ds_url | default(omit) }}"
database: "{{ datasource.database | default(omit) }}"
with_credentials: "{{ datasource.with_credentials | default(omit) }}"
is_default: "{{ datasource.is_default | default(omit) }}"
user: "{{ datasource.user | default(omit) }}"
password: "{{ datasource.password | default(omit) }}"
additional_json_data: "{{ datasource.additional_json_data | default(omit) }}"
additional_secure_json_data: "{{ datasource.additional_secure_json_data | default(omit) }}"
loop: "{{ grafana_datasources }}"
loop_control: {loop_var: datasource}
tags: datasource

- name: Manage folder
community.grafana.grafana_folder:
url: "{{ grafana_url }}"
url_username: "{{ grafana_username }}"
url_password: "{{ grafana_password }}"
name: "{{ folder.1 }}"
state: "{{ folder.0.state | default(omit) }}"
skip_version_check: "{{ folder.0.skip_version_check | default(omit) }}"
loop: "{{ grafana_folders | subelements('folder_object') }}"
loop_control:
loop_var: folder
name: "{{ folder.name }}"
state: "{{ folder.state | default(omit) }}"
skip_version_check: "{{ folder.skip_version_check | default(omit) }}"
loop: "{{ grafana_folders }}"
loop_control: {loop_var: folder}
tags: folder

- name: Manage team
community.grafana.grafana_team:
url: "{{ grafana_url }}"
url_username: "{{ grafana_username }}"
url_password: "{{ grafana_password }}"
name: "{{ team.1 }}"
email: "{{ team.0.email }}"
members: "{{ team.0.members | default(omit) }}"
state: "{{ team.0.state | default(omit) }}"
enforce_members: "{{ team.0.enforce_members | default(omit) }}"
skip_version_check: "{{ team.0.skip_version_check | default(omit) }}"
loop: "{{ grafana_teams | subelements('team_object') }}"
loop_control:
loop_var: team
name: "{{ team.name }}"
email: "{{ team.email }}"
members: "{{ team.members | default(omit) }}"
state: "{{ team.state | default(omit) }}"
enforce_members: "{{ team.enforce_members | default(omit) }}"
skip_version_check: "{{ team.skip_version_check | default(omit) }}"
loop: "{{ grafana_teams }}"
loop_control: {loop_var: team}
tags: team

- name: Manage user
community.grafana.grafana_user:
url: "{{ grafana_url }}"
url_username: "{{ grafana_username }}"
url_password: "{{ grafana_password }}"
name: "{{ user }}"
name: "{{ user.name }}"
email: "{{ user.email | default(omit) }}"
login: "{{ user.login }}"
password: "{{ user.password | default(omit) }}"
is_admin: "{{ user.is_admin | default(omit) }}"
state: "{{ user.state | default(omit) }}"
loop: "{{ grafana_users }}"
loop_control:
loop_var: user
loop_control: {loop_var: user}
tags: user

- name: Manage dashboard
community.grafana.grafana_dashboard:
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: "{{ dashboard.0.org_id | default(omit) }}"
folder: "{{ dashboard.0.folder | default(omit) }}"
state: "{{ dashboard.0.state | default(omit) }}"
slug: "{{ dashboard.0.slug | default(omit) }}"
uid: "{{ dashboard.0.uid | default(omit) }}"
path: "{{ dashboard.0.path | default(omit) }}"
overwrite: "{{ dashboard.0.overwrite | default(omit) }}"
dashboard_id: "{{ dashboard.0.dashboard_id | default(omit) }}"
dashboard_revision: "{{ dashboard.0.dashboard_revision | default(omit) }}"
commit_message: "{{ dashboard.0.commit_message | default(omit) }}"
loop: "{{ grafana_dashboards | subelements('dashboard_object') }}"
loop_control:
loop_var: dashboard
url: "{{ grafana_url }}"
url_username: "{{ grafana_username }}"
url_password: "{{ grafana_password }}"
org_id: "{{ dashboard.org_id | default(omit) }}"
folder: "{{ dashboard.folder | default(omit) }}"
state: "{{ dashboard.state | default(omit) }}"
slug: "{{ dashboard.slug | default(omit) }}"
uid: "{{ dashboard.uid | default(omit) }}"
path: "{{ dashboard.path | default(omit) }}"
overwrite: "{{ dashboard.overwrite | default(omit) }}"
dashboard_id: "{{ dashboard.dashboard_id | default(omit) }}"
dashboard_revision: "{{ dashboard.dashboard_revision | default(omit) }}"
commit_message: "{{ dashboard.commit_message | default(omit) }}"
loop: "{{ grafana_dashboards }}"
loop_control: {loop_var: dashboard}
tags: dashboard

Loading