From 05271d8edb1b2de095b172d20dae0d42c36b9b9c Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Mon, 6 Nov 2023 12:31:40 +0100 Subject: [PATCH 1/8] docs: added telekom-mms.grafana section --- README.md | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cfdfbc98..9b601a44 100644 --- a/README.md +++ b/README.md @@ -67,12 +67,9 @@ You can either call modules by their Fully Qualified Collection Namespace (FQCN) gather_facts: false connection: local - collections: - - community.grafana - tasks: - name: Ensure Influxdb datasource exists. - grafana_datasource: + community.grafana.grafana_datasource: name: "datasource-influxdb" grafana_url: "https://grafana.company.com" grafana_user: "admin" @@ -93,13 +90,11 @@ In your playbooks, you can set [module defaults](https://github.com/ansible/ansi ```yaml +--- - hosts: localhost gather_facts: false connection: local - collections: - - community.grafana - module_defaults: group/community.grafana.grafana: grafana_url: "https://grafana.company.com" @@ -108,7 +103,7 @@ In your playbooks, you can set [module defaults](https://github.com/ansible/ansi tasks: - name: Ensure Influxdb datasource exists. - grafana_datasource: + community.grafana.grafana_datasource: name: "datasource-influxdb" org_id: "1" ds_type: "influxdb" @@ -118,7 +113,7 @@ In your playbooks, you can set [module defaults](https://github.com/ansible/ansi tls_ca_cert: "/etc/ssl/certs/ca.pem" - name: Create or update a Grafana user - grafana_user: + community.grafana.grafana_user: name: "Bruce Wayne" email: "batman@gotham.city" login: "batman" @@ -126,6 +121,45 @@ In your playbooks, you can set [module defaults](https://github.com/ansible/ansi is_admin: true ``` +## Complementary Collection: [`telekom-mms.grafana`](https://github.com/telekom-mms/ansible-role-grafana) + +The `telekom-mms.grafana` collection is an Ansible Collection that simplifies the use of the `community.grafana` collection. It provides an Ansible Role for easy integration with `community.grafana`. With this collection, you only need to define the variables for your Grafana resources. + +### Requirements + ansible-galaxy collection install telekom-mms.grafana +... or use a requirements.yml: +`ansible-galaxy collection install -r requirements.yml` +```yaml +--- +collections: + - name: telekom-mms.grafana +``` + +### Example Playbook +```yaml +--- +- hosts: localhost + gather_facts: false + connection: local + + vars: + grafana_url: "https://grafana.company.com" + grafana_user: "admin" + grafana_password: "xxxxxx" + + grafana_datasources: + - name: "Loki" + ds_type: "loki" + ds_url: "http://127.0.0.1:3100" + tls_skip_verify: yes + grafana_folders: + - name: my_service + - name: other_service + + roles: + - role: telekom-mms.grafana +``` + ## Testing and Development If you want to develop new content for this collection or improve what's already here, the easiest way to work on the collection is to clone it into one of the configured [`COLLECTIONS_PATHS`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths), and work on it there. From d123cd7525b462e0cf66ad02cc2450b31b114619 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:44:36 +0000 Subject: [PATCH 2/8] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b601a44..3334529f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![](https://github.com/ansible-collections/grafana/workflows/CI/badge.svg?branch=master) [![Codecov](https://img.shields.io/codecov/c/github/ansible-collections/community.grafana)](https://codecov.io/gh/ansible-collections/community.grafana) -[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-20-orange.svg?style=flat-square)](#contributors-) This repo hosts the `community.grafana` Ansible Collection. @@ -253,6 +253,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Pierre
Pierre

🐛 MiksonX
MiksonX

🐛 Aliaksandr Mianzhynski
Aliaksandr Mianzhynski

💻 ⚠️ + Moritz
Moritz

🐛 From 7c8f520c4e61fbe115c417bb43239c613cee136c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:44:37 +0000 Subject: [PATCH 3/8] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index b7e51435..2c7b593a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -187,6 +187,15 @@ "code", "test" ] + }, + { + "login": "Nemental", + "name": "Moritz", + "avatar_url": "https://avatars.githubusercontent.com/u/15136847?v=4", + "profile": "https://nemental.de", + "contributions": [ + "bug" + ] } ], "contributorsPerLine": 7, @@ -195,5 +204,6 @@ "repoType": "github", "repoHost": "https://github.com", "skipCi": true, - "commitConvention": "angular" + "commitConvention": "angular", + "commitType": "docs" } From cd53136f8be51e639a78baab2a6cd54bbd8e262c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:48:29 +0000 Subject: [PATCH 4/8] docs: update README.md [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3334529f..ce32c493 100644 --- a/README.md +++ b/README.md @@ -253,7 +253,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Pierre
Pierre

🐛 MiksonX
MiksonX

🐛 Aliaksandr Mianzhynski
Aliaksandr Mianzhynski

💻 ⚠️ - Moritz
Moritz

🐛 + Moritz
Moritz

🐛 💻 From 21b6f4101e96247da04c61124c319a0740258a1b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:48:30 +0000 Subject: [PATCH 5/8] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 2c7b593a..f1a1cb6d 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -194,7 +194,8 @@ "avatar_url": "https://avatars.githubusercontent.com/u/15136847?v=4", "profile": "https://nemental.de", "contributions": [ - "bug" + "bug", + "code" ] } ], From 0100a21a4f537a381cdd5400ec810d57eb9059d9 Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Mon, 13 Nov 2023 16:40:52 +0100 Subject: [PATCH 6/8] default to true/false --- plugins/callback/grafana_annotations.py | 4 ++-- plugins/doc_fragments/basic_auth.py | 10 +++++----- plugins/modules/grafana_dashboard.py | 4 ++-- plugins/modules/grafana_datasource.py | 8 ++++---- plugins/modules/grafana_folder.py | 2 +- plugins/modules/grafana_notification_channel.py | 6 +++--- plugins/modules/grafana_plugin.py | 2 +- plugins/modules/grafana_team.py | 6 +++--- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/plugins/callback/grafana_annotations.py b/plugins/callback/grafana_annotations.py index 04555eae..92b837c1 100644 --- a/plugins/callback/grafana_annotations.py +++ b/plugins/callback/grafana_annotations.py @@ -29,7 +29,7 @@ options: grafana_url: description: Grafana annotations api URL - required: True + required: true env: - name: GRAFANA_URL ini: @@ -45,7 +45,7 @@ key: validate_grafana_certs - section: callback_grafana_annotations key: validate_certs - default: True + default: true type: bool aliases: [ validate_grafana_certs ] http_agent: diff --git a/plugins/doc_fragments/basic_auth.py b/plugins/doc_fragments/basic_auth.py index 8c41acdb..c874457d 100644 --- a/plugins/doc_fragments/basic_auth.py +++ b/plugins/doc_fragments/basic_auth.py @@ -30,9 +30,9 @@ class ModuleDocFragment(object): aliases: [ grafana_password ] use_proxy: description: - - If C(no), it will not use a proxy, even if one is defined in an environment variable on the target hosts. + - If C(false), it will not use a proxy, even if one is defined in an environment variable on the target hosts. type: bool - default: yes + default: true client_cert: description: - PEM formatted certificate chain file to be used for SSL client authentication. @@ -45,8 +45,8 @@ class ModuleDocFragment(object): type: path validate_certs: description: - - If C(no), SSL certificates will not be validated. - - This should only set to C(no) used on personally controlled sites using self-signed certificates. + - If C(false), SSL certificates will not be validated. + - This should only set to C(false) used on personally controlled sites using self-signed certificates. type: bool - default: yes + default: true ''' diff --git a/plugins/modules/grafana_dashboard.py b/plugins/modules/grafana_dashboard.py index cc2654f6..46d3aeb1 100644 --- a/plugins/modules/grafana_dashboard.py +++ b/plugins/modules/grafana_dashboard.py @@ -58,7 +58,7 @@ description: - Override existing dashboard when state is present. type: bool - default: 'no' + default: false dashboard_id: description: - Public Grafana.com dashboard id to import @@ -92,7 +92,7 @@ grafana_api_key: "{{ grafana_api_key }}" state: present commit_message: Updated by ansible - overwrite: yes + overwrite: true path: /path/to/dashboards/foo.json - name: Import Grafana dashboard Zabbix diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 5f865ec5..0b2d1b64 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -86,7 +86,7 @@ type: str basic_auth_password: description: - - The datasource basic auth password, when C(basic auth) is C(yes). + - The datasource basic auth password, when C(basic auth) is C(true). - Stored as secure data, see C(enforce_secure_data) and notes! type: str with_credentials: @@ -94,7 +94,7 @@ - Whether credentials such as cookies or auth headers should be sent with cross-site requests. type: bool - default: 'no' + default: false tls_client_cert: description: - The client TLS certificate. @@ -123,7 +123,7 @@ description: - Make this datasource the default one. type: bool - default: 'no' + default: false org_id: description: - Grafana Organisation ID in which the datasource should be created. @@ -217,7 +217,7 @@ description: - Use trends or not for zabbix datasource type. type: bool - default: False + default: false aws_auth_type: description: - Type for AWS authentication for CloudWatch datasource type (authType of grafana diff --git a/plugins/modules/grafana_folder.py b/plugins/modules/grafana_folder.py index 380a510c..4dcb8453 100644 --- a/plugins/modules/grafana_folder.py +++ b/plugins/modules/grafana_folder.py @@ -50,7 +50,7 @@ - This parameter can be useful if you enabled `hide_version` in grafana.ini required: False type: bool - default: False + default: false version_added: "1.2.0" extends_documentation_fragment: - community.grafana.basic_auth diff --git a/plugins/modules/grafana_notification_channel.py b/plugins/modules/grafana_notification_channel.py index eb808fa1..1913c290 100644 --- a/plugins/modules/grafana_notification_channel.py +++ b/plugins/modules/grafana_notification_channel.py @@ -82,17 +82,17 @@ - Required when I(state) is C(present). is_default: type: bool - default: 'no' + default: false description: - Use this channel for all alerts. include_image: type: bool - default: 'no' + default: false description: - Capture a visualization image and attach it to notifications. disable_resolve_message: type: bool - default: 'no' + default: false description: - Disable the resolve message. reminder_frequency: diff --git a/plugins/modules/grafana_plugin.py b/plugins/modules/grafana_plugin.py index 7fd41876..073de119 100644 --- a/plugins/modules/grafana_plugin.py +++ b/plugins/modules/grafana_plugin.py @@ -50,7 +50,7 @@ validate_certs: description: - Boolean variable to include --insecure while installing pluging - default: False + default: false type: bool ''' diff --git a/plugins/modules/grafana_team.py b/plugins/modules/grafana_team.py index 7f8de845..b7b2318d 100644 --- a/plugins/modules/grafana_team.py +++ b/plugins/modules/grafana_team.py @@ -59,7 +59,7 @@ description: - Delete the members not found in the C(members) parameters from the - list of members found on the Team. - default: False + default: false type: bool skip_version_check: description: @@ -67,7 +67,7 @@ - This parameter can be useful if you enabled `hide_version` in grafana.ini required: False type: bool - default: False + default: false version_added: "1.2.0" extends_documentation_fragment: - community.grafana.basic_auth @@ -104,7 +104,7 @@ members: - john.doe@example.com - jane.doe@example.com - enforce_members: yes + enforce_members: true state: present - name: Delete a team From c57b9cdfa4de326dd348310a77a59efa68c1ac46 Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Mon, 13 Nov 2023 16:52:04 +0100 Subject: [PATCH 7/8] add changelog fragment --- changelogs/fragments/325_true_false.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/325_true_false.yml diff --git a/changelogs/fragments/325_true_false.yml b/changelogs/fragments/325_true_false.yml new file mode 100644 index 00000000..c192d086 --- /dev/null +++ b/changelogs/fragments/325_true_false.yml @@ -0,0 +1,2 @@ +minor_changes: +- default to true/false in docs and code From 757d7ae6aa9180a42846a5e57e371395abe5c51a Mon Sep 17 00:00:00 2001 From: SHURAVIN Anatoly Date: Thu, 21 Dec 2023 13:48:03 +0300 Subject: [PATCH 8/8] Add tempo datasource support --- .../335-add-datasource-type-tempo.yml | 2 + plugins/modules/grafana_datasource.py | 4 +- .../grafana_datasource/tasks/tempo.yml | 78 +++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/335-add-datasource-type-tempo.yml create mode 100644 tests/integration/targets/grafana_datasource/tasks/tempo.yml diff --git a/changelogs/fragments/335-add-datasource-type-tempo.yml b/changelogs/fragments/335-add-datasource-type-tempo.yml new file mode 100644 index 00000000..18d34a0a --- /dev/null +++ b/changelogs/fragments/335-add-datasource-type-tempo.yml @@ -0,0 +1,2 @@ +minor_changes: + - Add support for Grafana Tempo datasource type (https://grafana.com/docs/grafana/latest/datasources/tempo/) \ No newline at end of file diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 0b2d1b64..f743303c 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -46,6 +46,7 @@ - camptocamp-prometheus-alertmanager-datasource - loki - redis-datasource + - tempo type: str ds_url: description: @@ -742,7 +743,8 @@ def setup_module_object(): 'camptocamp-prometheus-alertmanager-datasource', 'sni-thruk-datasource', 'redis-datasource', - 'loki']), + 'loki', + 'tempo']), ds_url=dict(type='str'), access=dict(default='proxy', choices=['proxy', 'direct']), database=dict(type='str', default=""), diff --git a/tests/integration/targets/grafana_datasource/tasks/tempo.yml b/tests/integration/targets/grafana_datasource/tasks/tempo.yml new file mode 100644 index 00000000..5065a6ce --- /dev/null +++ b/tests/integration/targets/grafana_datasource/tasks/tempo.yml @@ -0,0 +1,78 @@ +- name: Create tempo datasource + register: result + grafana_datasource: + name: datasource-tempo + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_username }}" + grafana_password: "{{ grafana_password }}" + org_id: '1' + ds_type: tempo + ds_url: tempo.company.com:3100 + +- debug: + var: result + +- assert: + that: + - result.changed + - "result.msg == 'Datasource datasource-tempo created'" + +- name: Check tempo datasource creation idempotency + register: result + grafana_datasource: + name: datasource-tempo + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_username }}" + grafana_password: "{{ grafana_password }}" + org_id: '1' + ds_type: tempo + ds_url: tempo.company.com:3100 + +- debug: + var: result + +- assert: + that: + - not result.changed + - result.datasource.basicAuth == false + - result.datasource.isDefault == false + - result.datasource.jsonData.tlsAuth == false + - result.datasource.jsonData.tlsAuthWithCACert == false + - result.datasource.secureJsonFields.httpHeaderValue1 == true + - result.datasource.name == 'datasource-tempo' + - result.datasource.orgId == 1 + - result.datasource.type == 'tempo' + - result.datasource.url == 'tempo.company.com:3100' + - result.datasource.withCredentials == false + +- name: Delete tempo datasource + register: result + grafana_datasource: + name: datasource-tempo + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_username }}" + grafana_password: "{{ grafana_password }}" + state: absent + +- debug: + var: result + +- assert: + that: + - result.changed + +- name: Delete tempo datasource + register: result + grafana_datasource: + name: datasource-tempo + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_username }}" + grafana_password: "{{ grafana_password }}" + state: absent + +- debug: + var: result + +- assert: + that: + - not result.changed