diff --git a/README.md b/README.md index b38275a..924bb6f 100644 --- a/README.md +++ b/README.md @@ -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 | @@ -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 | @@ -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 ``` diff --git a/defaults/main.yml b/defaults/main.yml index d3e5e96..5ee7817 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,5 @@ --- +grafana_organizations: [] grafana_users: [] grafana_teams: [] grafana_datasources: [] diff --git a/meta/main.yml b/meta/main.yml index 0879a70..676ba59 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -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]} diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 77b3705..6e3e513 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -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 diff --git a/requirements.yml b/requirements.yml index e69403c..364da58 100644 --- a/requirements.yml +++ b/requirements.yml @@ -1,3 +1,2 @@ -collections: -- name: community.grafana - version: 1.5.4 +--- +collections: [{name: community.grafana, version: 1.5.4}] diff --git a/tasks/main.yml b/tasks/main.yml index 937ebd3..e41e2f7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,26 +1,36 @@ --- +- 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 @@ -28,12 +38,11 @@ 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 @@ -41,15 +50,14 @@ 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 @@ -57,34 +65,31 @@ 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 -