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 13 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
52 changes: 30 additions & 22 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 @@ -62,21 +63,25 @@ community.grafana
| dashboard_id | no |
| dashboard_revision | no |
| commit_message | no |
<!--- community.grafana 1.6.0 release required
| [**grafana_organization_users**](https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_organization_user_module.html)
| login | yes |
| role | no |
| state | no |
| org_id | no |
--->

## 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:
Expand All @@ -89,4 +94,7 @@ community.grafana
- folder_object:
- my_service
- 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
24 changes: 6 additions & 18 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
---

Check failure on line 1 in meta/main.yml

View workflow job for this annotation

GitHub Actions / release / ansible-lint

schema[meta]

$.galaxy_info.min_ansible_version 2.9 is not of type 'string'. See https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse_roles.html#using-role-dependencies
galaxy_info:
role_name: grafana
author: telekom_mms
description: Configure Grafana dashboards, folders, datasources, teams and users
license: GPLv3
min_ansible_version: 2.9
galaxy_tags:
- grafana
- monitoring
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]}
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}]
137 changes: 74 additions & 63 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,101 @@
---
# datasource.0 = grafana_datasource attribute
- name: Manage datasource
community.grafana.grafana_datasource:
- name: Grafana connection anchor
ansible.builtin.set_fact: &grafana_connection
Nemental marked this conversation as resolved.
Show resolved Hide resolved
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

- name: Manage organization
community.grafana.grafana_organization:
<<: *grafana_connection
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:
<<: *grafana_connection
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
<<: *grafana_connection
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
<<: *grafana_connection
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 }}"
<<: *grafana_connection
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

### community.grafana 1.6.0 release required
# - name: Manage organization user
# community.grafana.grafana_organization_user:
# <<: *grafana_connection
# login: "{{ organization_user.login }}"
# role: "{{ organization_user.role | default(omit) }}"
# state: "{{ organization_user.state | default(omit) }}"
# org_id: "{{ organization_user.org_id | default(omit) }}"
# loop: "{{ grafana_organization_users }}"
# loop_control: {loop_var: organization_user}
# tags: organization_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
<<: *grafana_connection
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