summaryrefslogtreecommitdiffstats
path: root/ansible_collections/community/grafana/tests/integration/targets
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:04:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:04:41 +0000
commit975f66f2eebe9dadba04f275774d4ab83f74cf25 (patch)
tree89bd26a93aaae6a25749145b7e4bca4a1e75b2be /ansible_collections/community/grafana/tests/integration/targets
parentInitial commit. (diff)
downloadansible-975f66f2eebe9dadba04f275774d4ab83f74cf25.tar.xz
ansible-975f66f2eebe9dadba04f275774d4ab83f74cf25.zip
Adding upstream version 7.7.0+dfsg.upstream/7.7.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/community/grafana/tests/integration/targets')
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/aliases1
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/defaults/main.yml7
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/files/dashboard.json85
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-export.yml33
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-folder-destination.yml33
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-file.yml44
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-id.yml40
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-url.yml39
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/delete-dashboard.yml16
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/main.yml7
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/aliases1
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/defaults/main.yml7
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/azure.yml123
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/cloudwatch.yml111
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/elastic.yml313
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/errors.yml18
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/influx.yml88
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/issues.yml46
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/loki.yml82
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/main.yml16
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/postgres.yml93
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/redis.yml101
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/thruk.yml78
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/uid.yml253
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/zabbix.yml114
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_folder/defaults/main.yml7
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_folder/tasks/main.yml55
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/defaults/main.yml7
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/dingding.yml74
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/discord.yml74
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/email.yml79
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/googlechat.yml74
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/hipchat.yml74
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/kafka.yml76
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/line.yml74
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/main.yml20
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/opsgenie.yml77
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/pagerduty.yml74
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/prometheus.yml74
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/pushover.yml76
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/sensu.yml74
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/slack-and-beyond.yml110
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/teams.yml74
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/telegram.yml76
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/threema.yml78
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/victorops.yml74
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/webhook.yml74
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_organization/defaults/main.yml4
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_organization/tasks/main.yml57
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_team/defaults/main.yml7
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_team/tasks/create_user.yml29
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_team/tasks/main.yml187
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_user/defaults/main.yml4
-rw-r--r--ansible_collections/community/grafana/tests/integration/targets/grafana_user/tasks/main.yml237
54 files changed, 3749 insertions, 0 deletions
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/aliases b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/aliases
new file mode 100644
index 000000000..a6dafcf8c
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/aliases
@@ -0,0 +1 @@
+shippable/posix/group1
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/defaults/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/defaults/main.yml
new file mode 100644
index 000000000..8b9c9348a
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/defaults/main.yml
@@ -0,0 +1,7 @@
+---
+
+grafana_url: "http://grafana:3000/"
+grafana_username: "admin"
+grafana_password: "admin"
+
+...
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/files/dashboard.json b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/files/dashboard.json
new file mode 100644
index 000000000..70287fa74
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/files/dashboard.json
@@ -0,0 +1,85 @@
+{
+ "annotations": {
+ "list": [
+ {
+ "builtIn": 1,
+ "datasource": "-- Grafana --",
+ "enable": true,
+ "hide": true,
+ "iconColor": "rgba(0, 211, 255, 1)",
+ "name": "Annotations & Alerts",
+ "type": "dashboard"
+ }
+ ]
+ },
+ "editable": true,
+ "gnetId": null,
+ "graphTooltip": 0,
+ "id": 11,
+ "links": [],
+ "panels": [
+ {
+ "content": "\n# Title\n\nFor markdown syntax help: [commonmark.org/help](https://commonmark.org/help/)\n\n\n\n",
+ "gridPos": {
+ "h": 9,
+ "w": 12,
+ "x": 0,
+ "y": 0
+ },
+ "id": 2,
+ "mode": "markdown",
+ "options": {},
+ "targets": [
+ {
+ "expr": "",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "refId": "A"
+ }
+ ],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Panel Title",
+ "type": "text"
+ }
+ ],
+ "schemaVersion": 18,
+ "style": "dark",
+ "tags": [],
+ "templating": {
+ "list": []
+ },
+ "time": {
+ "from": "now-6h",
+ "to": "now"
+ },
+ "timepicker": {
+ "refresh_intervals": [
+ "5s",
+ "10s",
+ "30s",
+ "1m",
+ "5m",
+ "15m",
+ "30m",
+ "1h",
+ "2h",
+ "1d"
+ ],
+ "time_options": [
+ "5m",
+ "15m",
+ "1h",
+ "6h",
+ "12h",
+ "24h",
+ "2d",
+ "7d",
+ "30d"
+ ]
+ },
+ "timezone": "",
+ "title": "test",
+ "uid": "9ZlJIhhWk",
+ "version": 7
+ } \ No newline at end of file
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-export.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-export.yml
new file mode 100644
index 000000000..04b17f727
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-export.yml
@@ -0,0 +1,33 @@
+---
+- set_fact:
+ dashboard_uid: "{{ result.uid }}"
+
+- name: Check export grafana dashboard to file
+ grafana_dashboard:
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: export
+ path: /tmp/dashboard.json
+ overwrite: true
+ uid: "{{ dashboard_uid }}"
+ register: result
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.msg == 'Dashboard {{ dashboard_uid }} exported to /tmp/dashboard.json'"
+
+- name: Load /tmp/dashboard.json or fail if missing
+ set_fact:
+ exported_dashboard_lines: "{{ lookup('file', '/tmp/dashboard.json').splitlines() }}"
+
+- name: Assert that exported dashboard contains formatted JSON
+ assert:
+ that:
+ - "exported_dashboard_lines | length >= 2"
+ - "exported_dashboard_lines[0] == '{'"
+ - "exported_dashboard_lines[-1] == '}'"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-folder-destination.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-folder-destination.yml
new file mode 100644
index 000000000..f4f3d9f4d
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-folder-destination.yml
@@ -0,0 +1,33 @@
+---
+- name: copy dashboard file
+ copy:
+ src: "files/dashboard.json"
+ dest: "/tmp/dashboard.json"
+
+- block:
+ - name: Check import grafana dashboard from file to unknown folder fails
+ grafana_dashboard:
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: present
+ commit_message: Updated by ansible
+ path: /tmp/dashboard.json
+ overwrite: true
+ folder: inexistent
+ register: result
+ ignore_errors: true
+
+- debug:
+ var: result
+
+- set_fact:
+ # XXX: Too many quotes of different types to do inline.
+ # I did not manage to find a good way of having it inline.
+ expected_error: "error : Dashboard folder 'inexistent' does not exist."
+
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.failed == true"
+ - "result.msg == expected_error"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-file.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-file.yml
new file mode 100644
index 000000000..93df1666a
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-file.yml
@@ -0,0 +1,44 @@
+---
+- name: copy dashboard file
+ copy:
+ src: "files/dashboard.json"
+ dest: "/tmp/dashboard.json"
+
+
+- name: Check import grafana dashboard from file
+ grafana_dashboard:
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: present
+ commit_message: Updated by ansible
+ path: /tmp/dashboard.json
+ overwrite: true
+ register: result
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.msg == 'Dashboard test created'"
+
+- name: Check import grafana dashboard from file idempotency
+ grafana_dashboard:
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: present
+ commit_message: Updated by ansible
+ path: /tmp/dashboard.json
+ overwrite: true
+ register: result
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.msg == 'Dashboard test unchanged.'"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-id.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-id.yml
new file mode 100644
index 000000000..3b81ebf71
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-id.yml
@@ -0,0 +1,40 @@
+---
+- name: Check import grafana dashboard from id
+ grafana_dashboard:
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: present
+ commit_message: Updated by ansible
+ dashboard_id: "6098"
+ dashboard_revision: "1"
+ overwrite: true
+ register: result
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.msg == 'Dashboard Zabbix Host Status created'"
+
+- name: Check import grafana dashboard from id idempotency
+ grafana_dashboard:
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: present
+ commit_message: Updated by ansible
+ dashboard_id: "6098"
+ dashboard_revision: "1"
+ overwrite: true
+ register: result
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.msg == 'Dashboard Zabbix Host Status unchanged.'"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-url.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-url.yml
new file mode 100644
index 000000000..5146fc9a0
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/dashboard-from-url.yml
@@ -0,0 +1,39 @@
+---
+
+- name: Check import grafana dashboard from url
+ grafana_dashboard:
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: present
+ commit_message: Updated by ansible
+ dashboard_url: https://grafana.com/api/dashboards/6098/revisions/1/download
+ overwrite: true
+ register: result
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.msg == 'Dashboard Zabbix Host Status created'"
+
+- name: Check import grafana dashboard from url idempotency
+ grafana_dashboard:
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: present
+ commit_message: Updated by ansible
+ dashboard_url: https://grafana.com/api/dashboards/6098/revisions/1/download
+ overwrite: true
+ register: result
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.msg == 'Dashboard Zabbix Host Status unchanged.'"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/delete-dashboard.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/delete-dashboard.yml
new file mode 100644
index 000000000..2013324fb
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/delete-dashboard.yml
@@ -0,0 +1,16 @@
+- name: Check delete dashboard is working
+ grafana_dashboard:
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+ uid: "{{ result.uid }}"
+ register: result
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.msg == 'Dashboard {{ result.uid }} deleted'"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/main.yml
new file mode 100644
index 000000000..4d9138fcf
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_dashboard/tasks/main.yml
@@ -0,0 +1,7 @@
+- block:
+ - include: dashboard-from-url.yml
+ - include: delete-dashboard.yml
+ - include: dashboard-from-id.yml
+ - include: dashboard-from-file.yml
+ - include: dashboard-export.yml
+ - include: dashboard-folder-destination.yml
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/aliases b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/aliases
new file mode 100644
index 000000000..a6dafcf8c
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/aliases
@@ -0,0 +1 @@
+shippable/posix/group1
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/defaults/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/defaults/main.yml
new file mode 100644
index 000000000..8b9c9348a
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/defaults/main.yml
@@ -0,0 +1,7 @@
+---
+
+grafana_url: "http://grafana:3000/"
+grafana_username: "admin"
+grafana_password: "admin"
+
+...
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/azure.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/azure.yml
new file mode 100644
index 000000000..a96691893
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/azure.yml
@@ -0,0 +1,123 @@
+- name: Create azure datasource
+ register: result
+ grafana_datasource:
+ name: datasource-azure
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+ org_id: '1'
+ ds_type: grafana-azure-monitor-datasource
+ ds_url: http://example.com
+ azure_client: client1
+ azure_tenant: tenant1
+ azure_secret: secret1
+ azure_cloud: azuremonitor
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - "result.msg == 'Datasource datasource-azure created'"
+ - result.datasource.access == 'proxy'
+ - result.datasource.basicAuth == false
+ - result.datasource.database == ''
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.clientId == 'client1'
+ - result.datasource.jsonData.cloudName == 'azuremonitor'
+ - result.datasource.jsonData.tenantId == 'tenant1'
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.jsonData.tlsAuthWithCACert == false
+ - result.datasource.name == 'datasource-azure'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'grafana-azure-monitor-datasource'
+ - result.datasource.url == 'http://example.com'
+ - result.datasource.user == ''
+ - result.datasource.withCredentials == false
+
+- name: Check azure datasource creation idempotency
+ register: result
+ grafana_datasource:
+ name: datasource-azure
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+ org_id: '1'
+ ds_type: grafana-azure-monitor-datasource
+ ds_url: http://example.com
+ azure_client: client1
+ azure_tenant: tenant1
+ azure_secret: secret1
+ azure_cloud: azuremonitor
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
+ - result.datasource.access == 'proxy'
+ - result.datasource.basicAuth == false
+ - result.datasource.database == ''
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.clientId == 'client1'
+ - result.datasource.jsonData.cloudName == 'azuremonitor'
+ - result.datasource.jsonData.tenantId == 'tenant1'
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.jsonData.tlsAuthWithCACert == false
+ - result.datasource.name == 'datasource-azure'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'grafana-azure-monitor-datasource'
+ - result.datasource.url == 'http://example.com'
+ - result.datasource.user == ''
+ - result.datasource.withCredentials == false
+
+- name: Delete azure datasource
+ register: result
+ grafana_datasource:
+ name: datasource-azure
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+ org_id: '1'
+ ds_type: grafana-azure-monitor-datasource
+ ds_url: http://example.com
+ azure_client: client1
+ azure_tenant: tenant1
+ azure_secret: secret1
+ azure_cloud: azuremonitor
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - "result.msg == 'Datasource datasource-azure deleted.'"
+
+- name: Delete azure datasource (idempotency)
+ register: result
+ grafana_datasource:
+ name: datasource-azure
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+ org_id: '1'
+ ds_type: grafana-azure-monitor-datasource
+ ds_url: http://example.com
+ azure_client: client1
+ azure_tenant: tenant1
+ azure_secret: secret1
+ azure_cloud: azuremonitor
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/cloudwatch.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/cloudwatch.yml
new file mode 100644
index 000000000..50268ea8f
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/cloudwatch.yml
@@ -0,0 +1,111 @@
+- name: Create cloudwatch datasource
+ register: result
+ grafana_datasource:
+ name: datasource-cloudwatch
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+ org_id: '1'
+ ds_type: cloudwatch
+ ds_url: http://monitoring.us-west-1.amazonaws.com
+ aws_auth_type: keys
+ aws_default_region: us-west-1
+ aws_access_key: speakFriendAndEnter
+ aws_secret_key: mel10n
+ aws_custom_metrics_namespaces: n1,n2
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - "result.msg == 'Datasource datasource-cloudwatch created'"
+ - result.datasource.access == 'proxy'
+ - result.datasource.basicAuth == false
+ - result.datasource.database == ''
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.authType == 'keys'
+ - result.datasource.jsonData.customMetricsNamespaces == 'n1,n2'
+ - result.datasource.jsonData.defaultRegion == 'us-west-1'
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.jsonData.tlsAuthWithCACert == false
+ - result.datasource.name == 'datasource-cloudwatch'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'cloudwatch'
+ - result.datasource.url == 'http://monitoring.us-west-1.amazonaws.com'
+ - result.datasource.user == ''
+ - result.datasource.withCredentials == false
+
+- name: Check cloudwatch datasource creation idempotency
+ register: result
+ grafana_datasource:
+ name: datasource-cloudwatch
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: cloudwatch
+ ds_url: http://monitoring.us-west-1.amazonaws.com
+ aws_auth_type: keys
+ aws_default_region: us-west-1
+ aws_access_key: speakFriendAndEnter
+ aws_secret_key: mel10n
+ aws_custom_metrics_namespaces: n1,n2
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
+ - result.datasource.access == 'proxy'
+ - result.datasource.basicAuth == false
+ - result.datasource.database == ''
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.authType == 'keys'
+ - result.datasource.jsonData.customMetricsNamespaces == 'n1,n2'
+ - result.datasource.jsonData.defaultRegion == 'us-west-1'
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.jsonData.tlsAuthWithCACert == false
+ - result.datasource.name == 'datasource-cloudwatch'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'cloudwatch'
+ - result.datasource.url == 'http://monitoring.us-west-1.amazonaws.com'
+ - result.datasource.user == ''
+ - result.datasource.withCredentials == false
+
+- name: Delete cloudwatch datasource
+ register: result
+ grafana_datasource:
+ name: datasource-cloudwatch
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - "result.msg == 'Datasource datasource-cloudwatch deleted.'"
+
+- name: Delete cloudwatch datasource (idempotency)
+ register: result
+ grafana_datasource:
+ name: datasource-cloudwatch
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/elastic.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/elastic.yml
new file mode 100644
index 000000000..73b258426
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/elastic.yml
@@ -0,0 +1,313 @@
+---
+- name: Create elasticsearch datasource with legacy elasticsearch format
+ register: result
+ grafana_datasource:
+ name: "datasource/elasticLegacy"
+ uid: "myuid"
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: elasticsearch
+ ds_url: https://elastic.company.com:9200
+ database: '[logstash_]YYYY.MM.DD'
+ basic_auth_user: grafana
+ basic_auth_password: '******'
+ time_field: '@timestamp'
+ time_interval: 1m
+ interval: Daily
+ es_version: 56
+ max_concurrent_shard_requests: 42
+ tls_ca_cert: /etc/ssl/certs/ca.pem
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - result.datasource.basicAuth
+ - result.datasource.basicAuthUser == 'grafana'
+ - result.datasource.access == 'proxy'
+ - result.datasource.database == '[logstash_]YYYY.MM.DD'
+ - not result.datasource.isDefault
+ - result.datasource.jsonData.esVersion == 56
+ - result.datasource.jsonData.interval == 'Daily'
+ - result.datasource.jsonData.maxConcurrentShardRequests == 42
+ - result.datasource.jsonData.timeField == '@timestamp'
+ - not result.datasource.jsonData.tlsAuth
+ - result.datasource.jsonData.tlsAuthWithCACert
+ - result.datasource.name == 'datasource/elasticLegacy'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'elasticsearch'
+ - result.datasource.url == 'https://elastic.company.com:9200'
+ - result.datasource.user == ''
+ - not result.datasource.withCredentials
+ - "result.msg == 'Datasource datasource/elasticLegacy created'"
+
+- name: Create elasticsearch datasource with new elsaticsearch version format
+ register: result
+ grafana_datasource:
+ name: "datasource/elastic"
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: elasticsearch
+ ds_url: https://elastic.company.com:9200
+ database: '[logstash_]YYYY.MM.DD'
+ basic_auth_user: grafana
+ basic_auth_password: '******'
+ time_field: '@timestamp'
+ time_interval: 1m
+ interval: Daily
+ es_version: "7.10+"
+ max_concurrent_shard_requests: 42
+ tls_ca_cert: /etc/ssl/certs/ca.pem
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - result.datasource.basicAuth
+ - result.datasource.basicAuthUser == 'grafana'
+ - result.datasource.access == 'proxy'
+ - result.datasource.database == '[logstash_]YYYY.MM.DD'
+ - not result.datasource.isDefault
+ - result.datasource.jsonData.esVersion == "7.10.0"
+ - result.datasource.jsonData.interval == 'Daily'
+ - result.datasource.jsonData.maxConcurrentShardRequests == 42
+ - result.datasource.jsonData.timeField == '@timestamp'
+ - not result.datasource.jsonData.tlsAuth
+ - result.datasource.jsonData.tlsAuthWithCACert
+ - result.datasource.name == 'datasource/elastic'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'elasticsearch'
+ - result.datasource.url == 'https://elastic.company.com:9200'
+ - result.datasource.user == ''
+ - not result.datasource.withCredentials
+ - "result.msg == 'Datasource datasource/elastic created'"
+
+- name: Check elasticsearch datasource creation idempotency
+ register: result
+ grafana_datasource:
+ name: "datasource/elastic"
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: elasticsearch
+ ds_url: https://elastic.company.com:9200
+ database: '[logstash_]YYYY.MM.DD'
+ basic_auth_user: grafana
+ basic_auth_password: '******'
+ time_field: '@timestamp'
+ time_interval: 1m
+ interval: Daily
+ es_version: "7.10+"
+ max_concurrent_shard_requests: 42
+ tls_ca_cert: /etc/ssl/certs/ca.pem
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
+ - result.datasource.basicAuth
+ - result.datasource.basicAuthUser == 'grafana'
+ - result.datasource.access == 'proxy'
+ - result.datasource.database == '[logstash_]YYYY.MM.DD'
+ - not result.datasource.isDefault
+ - result.datasource.jsonData.esVersion == '7.10.0'
+ - result.datasource.jsonData.interval == 'Daily'
+ - result.datasource.jsonData.maxConcurrentShardRequests == 42
+ - result.datasource.jsonData.timeField == '@timestamp'
+ - not result.datasource.jsonData.tlsAuth
+ - result.datasource.jsonData.tlsAuthWithCACert
+ - result.datasource.name == 'datasource/elastic'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'elasticsearch'
+ - result.datasource.url == 'https://elastic.company.com:9200'
+ - result.datasource.user == ''
+ - not result.datasource.withCredentials
+
+- name: update elasticsearch datasource creation
+ register: result
+ grafana_datasource:
+ name: "datasource/elastic"
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: elasticsearch
+ ds_url: https://elastic.example.com:9200
+ database: '[logstash_]YYYY.MM.DD'
+ basic_auth_user: grafana
+ basic_auth_password: '******'
+ time_field: '@timestamp'
+ time_interval: 1m
+ interval: Daily
+ es_version: "7.10+"
+ max_concurrent_shard_requests: 42
+ tls_ca_cert: /etc/ssl/certs/ca.pem
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - result.datasource.basicAuth
+ - result.datasource.basicAuthUser == 'grafana'
+ - result.datasource.access == 'proxy'
+ - result.datasource.database == '[logstash_]YYYY.MM.DD'
+ - not result.datasource.isDefault
+ - result.datasource.jsonData.esVersion == '7.10.0'
+ - result.datasource.jsonData.interval == 'Daily'
+ - result.datasource.jsonData.maxConcurrentShardRequests == 42
+ - result.datasource.jsonData.timeField == '@timestamp'
+ - not result.datasource.jsonData.tlsAuth
+ - result.datasource.jsonData.tlsAuthWithCACert
+ - result.datasource.name == 'datasource/elastic'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'elasticsearch'
+ - result.datasource.url == 'https://elastic.example.com:9200'
+ - result.datasource.user == ''
+ - not result.datasource.withCredentials
+
+- name: update elasticsearch datasource (ignoring secureJsonData)
+ register: result
+ grafana_datasource:
+ name: "datasource/elastic"
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: elasticsearch
+ ds_url: https://elastic.example.com:9200
+ database: '[logstash_]YYYY.MM.DD'
+ basic_auth_user: grafana
+ basic_auth_password: '******'
+ time_field: '@timestamp'
+ time_interval: 1m
+ interval: Daily
+ es_version: "7.10+"
+ max_concurrent_shard_requests: 42
+ tls_ca_cert: /etc/ssl/certs/ca.pem
+ enforce_secure_data: false
+ additional_json_data:
+ nonSecureTest: "nonsecure"
+ additional_secure_json_data:
+ secureTest: "secure"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - result.datasource.basicAuth
+ - result.datasource.basicAuthUser == 'grafana'
+ - result.datasource.access == 'proxy'
+ - result.datasource.database == '[logstash_]YYYY.MM.DD'
+ - not result.datasource.isDefault
+ - result.datasource.jsonData.esVersion == '7.10.0'
+ - result.datasource.jsonData.interval == 'Daily'
+ - result.datasource.jsonData.maxConcurrentShardRequests == 42
+ - result.datasource.jsonData.timeField == '@timestamp'
+ - not result.datasource.jsonData.tlsAuth
+ - result.datasource.jsonData.tlsAuthWithCACert
+ - result.datasource.name == 'datasource/elastic'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'elasticsearch'
+ - result.datasource.url == 'https://elastic.example.com:9200'
+ - result.datasource.user == ''
+ - not result.datasource.withCredentials
+ - result.datasource.jsonData.nonSecureTest == 'nonsecure'
+
+- name: update elasticsearch datasource (including secureJsonData)
+ register: result
+ grafana_datasource:
+ name: "datasource/elastic"
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: elasticsearch
+ ds_url: https://elastic.example.com:9200
+ database: '[logstash_]YYYY.MM.DD'
+ basic_auth_user: grafana
+ basic_auth_password: '******'
+ time_field: '@timestamp'
+ time_interval: 1m
+ interval: Daily
+ es_version: "7.10+"
+ max_concurrent_shard_requests: 42
+ tls_ca_cert: /etc/ssl/certs/ca.pem
+ enforce_secure_data: true
+ additional_json_data:
+ nonSecureTest: "nonsecure"
+ additional_secure_json_data:
+ secureTest: "secure"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - result.datasource.basicAuth
+ - result.datasource.basicAuthUser == 'grafana'
+ - result.datasource.access == 'proxy'
+ - result.datasource.database == '[logstash_]YYYY.MM.DD'
+ - not result.datasource.isDefault
+ - result.datasource.jsonData.esVersion == '7.10.0'
+ - result.datasource.jsonData.interval == 'Daily'
+ - result.datasource.jsonData.maxConcurrentShardRequests == 42
+ - result.datasource.jsonData.timeField == '@timestamp'
+ - not result.datasource.jsonData.tlsAuth
+ - result.datasource.jsonData.tlsAuthWithCACert
+ - result.datasource.name == 'datasource/elastic'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'elasticsearch'
+ - result.datasource.url == 'https://elastic.example.com:9200'
+ - result.datasource.user == ''
+ - not result.datasource.withCredentials
+ - result.datasource.jsonData.nonSecureTest == 'nonsecure'
+ - result.datasource.secureJsonFields.secureTest == true
+ - result.diff.after.secureJsonData is defined
+
+- name: Delete elasticsearch datasource
+ register: result
+ grafana_datasource:
+ name: "datasource/elastic"
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- assert:
+ that:
+ - result.changed
+
+- name: Delete elasticsearch datasource (idempotency)
+ register: result
+ grafana_datasource:
+ name: "datasource/elastic"
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- assert:
+ that:
+ - not result.changed
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/errors.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/errors.yml
new file mode 100644
index 000000000..731a19d8f
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/errors.yml
@@ -0,0 +1,18 @@
+---
+- name: Create datasource without `ds_type` and `ds_url` (expect failure)
+ register: result
+ grafana_datasource:
+ name: datasource-postgres
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ ignore_errors: true
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
+ - result.failed
+ - "result.msg == 'state is present but all of the following are missing: ds_type, ds_url'"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/influx.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/influx.yml
new file mode 100644
index 000000000..da61833f6
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/influx.yml
@@ -0,0 +1,88 @@
+- name: Create influxdb datasource
+ register: result
+ grafana_datasource:
+ name: datasource-influxdb
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: influxdb
+ ds_url: https://influx.company.com:8086
+ database: telegraf
+ time_interval: '>10s'
+ tls_ca_cert: /etc/ssl/certs/ca.pem
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - "result.msg == 'Datasource datasource-influxdb created'"
+
+- name: Check influxdb datasource creation idempotency
+ register: result
+ grafana_datasource:
+ name: datasource-influxdb
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: influxdb
+ ds_url: https://influx.company.com:8086
+ database: telegraf
+ time_interval: '>10s'
+ tls_ca_cert: /etc/ssl/certs/ca.pem
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
+ - result.datasource.basicAuth == false
+ - result.datasource.access == 'proxy'
+ - result.datasource.database == 'telegraf'
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.timeInterval == '>10s'
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.jsonData.tlsAuthWithCACert
+ - result.datasource.name == 'datasource-influxdb'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'influxdb'
+ - result.datasource.url == 'https://influx.company.com:8086'
+ - result.datasource.user == ''
+ - result.datasource.withCredentials == false
+
+- name: Delete influxdb datasource
+ register: result
+ grafana_datasource:
+ name: datasource-influxdb
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+
+- name: Delete influxdb datasource (idempotency)
+ register: result
+ grafana_datasource:
+ name: datasource-influxdb
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/issues.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/issues.yml
new file mode 100644
index 000000000..f80677d8d
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/issues.yml
@@ -0,0 +1,46 @@
+---
+
+- name: test datasource name with slash
+ register: result
+ grafana_datasource:
+ name: "datasource/elastic"
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: elasticsearch
+ ds_url: https://elastic.company.com:9200
+ database: '[logstash_]YYYY.MM.DD'
+ basic_auth_user: grafana
+ basic_auth_password: '******'
+ time_field: '@timestamp'
+ time_interval: 1m
+ interval: Daily
+ es_version: 56
+ max_concurrent_shard_requests: 42
+ tls_ca_cert: /etc/ssl/certs/ca.pem
+
+- assert:
+ that:
+ - result.changed
+ - result.datasource.basicAuth
+ - result.datasource.basicAuthUser == 'grafana'
+ - result.datasource.access == 'proxy'
+ - result.datasource.database == '[logstash_]YYYY.MM.DD'
+ - not result.datasource.isDefault
+ - result.datasource.jsonData.esVersion == 56
+ - result.datasource.jsonData.interval == 'Daily'
+ - result.datasource.jsonData.maxConcurrentShardRequests == 42
+ - result.datasource.jsonData.timeField == '@timestamp'
+ - not result.datasource.jsonData.tlsAuth
+ - not result.datasource.jsonData.tlsAuthWithCACert
+ - result.datasource.name == 'datasource/elastic'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'elasticsearch'
+ - result.datasource.url == 'https://elastic.company.com:9200'
+ - result.datasource.user == ''
+ - not result.datasource.withCredentials
+ - "result.msg == 'Datasource datasource/elastic created'"
+
+...
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/loki.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/loki.yml
new file mode 100644
index 000000000..68eca9802
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/loki.yml
@@ -0,0 +1,82 @@
+- name: Create loki datasource
+ register: result
+ grafana_datasource:
+ name: datasource-loki
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+ org_id: '1'
+ ds_type: loki
+ ds_url: https://loki.company.com:3100
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - "result.msg == 'Datasource datasource-loki created'"
+
+- name: Check loki datasource creation idempotency
+ register: result
+ grafana_datasource:
+ name: datasource-loki
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: loki
+ ds_url: https://loki.company.com:3100
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
+ - result.datasource.basicAuth == false
+ - result.datasource.access == 'proxy'
+ - result.datasource.database == ''
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.jsonData.tlsAuthWithCACert == false
+ - result.datasource.name == 'datasource-loki'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'loki'
+ - result.datasource.url == 'https://loki.company.com:3100'
+ - result.datasource.user == ''
+ - result.datasource.withCredentials == false
+
+- name: Delete loki datasource
+ register: result
+ grafana_datasource:
+ name: datasource-loki
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - "result.msg == 'Datasource datasource-loki deleted.'"
+
+- name: Delete loki datasource (idempotency)
+ register: result
+ grafana_datasource:
+ name: datasource-loki
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/main.yml
new file mode 100644
index 000000000..b5798e9a8
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/main.yml
@@ -0,0 +1,16 @@
+---
+
+- block:
+ - include: errors.yml
+ - include: elastic.yml
+ - include: influx.yml
+ - include: postgres.yml
+ - include: cloudwatch.yml
+ - include: thruk.yml
+ - include: loki.yml
+ - include: zabbix.yml
+ - include: redis.yml
+ - include: azure.yml
+ - include: uid.yml
+
+...
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/postgres.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/postgres.yml
new file mode 100644
index 000000000..80221f012
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/postgres.yml
@@ -0,0 +1,93 @@
+- name: Create postgres datasource
+ register: result
+ grafana_datasource:
+ name: datasource-postgres
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: postgres
+ ds_url: postgres.company.com:5432
+ database: db
+ user: postgres
+ password: iampgroot
+ sslmode: verify-full
+ additional_json_data:
+ timescaledb: true
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - "result.msg == 'Datasource datasource-postgres created'"
+
+- name: Check postgres datasource creation idempotency
+ register: result
+ grafana_datasource:
+ name: datasource-postgres
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: postgres
+ ds_url: postgres.company.com:5432
+ database: db
+ user: postgres
+ password: iampgroot
+ sslmode: verify-full
+ additional_json_data:
+ timescaledb: true
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
+ - result.datasource.basicAuth == false
+ - result.datasource.database == 'db'
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.sslmode == 'verify-full'
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.jsonData.tlsAuthWithCACert == false
+ - result.datasource.jsonData.timescaledb == true
+ - result.datasource.name == 'datasource-postgres'
+ - result.datasource.orgId == 1
+ - result.datasource.type == 'postgres'
+ - result.datasource.url == 'postgres.company.com:5432'
+ - result.datasource.user == 'postgres'
+ - result.datasource.withCredentials == false
+
+- name: Delete postgres datasource
+ register: result
+ grafana_datasource:
+ name: datasource-postgres
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+
+- name: Delete postgres datasource
+ register: result
+ grafana_datasource:
+ name: datasource-postgres
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/redis.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/redis.yml
new file mode 100644
index 000000000..933695354
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/redis.yml
@@ -0,0 +1,101 @@
+- name: Create redis datasource
+ register: result
+ grafana_datasource:
+ name: datasource-redis
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: redis-datasource
+ ds_url: https://redis.company.com:6379
+ time_interval: 1m
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - result.datasource.access == 'proxy'
+ - not result.datasource.isDefault
+ - result.datasource.name == 'datasource-redis'
+ - result.datasource.orgId == 1
+ - result.datasource.type == 'redis-datasource'
+ - result.datasource.url == 'https://redis.company.com:6379'
+ - "result.msg == 'Datasource datasource-redis created'"
+
+- name: Check redis-datasource datasource creation idempotency
+ register: result
+ grafana_datasource:
+ name: datasource-redis
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: redis-datasource
+ ds_url: https://redis.company.com:6379
+ time_interval: 1m
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
+ - result.datasource.access == 'proxy'
+ - not result.datasource.isDefault
+ - result.datasource.name == 'datasource-redis'
+ - result.datasource.orgId == 1
+ - result.datasource.type == 'redis-datasource'
+ - result.datasource.url == 'https://redis.company.com:6379'
+
+- name: update redis-datasource datasource creation
+ register: result
+ grafana_datasource:
+ name: datasource-redis
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: redis-datasource
+ ds_url: https://redisnew.company.com:6379
+ time_interval: 1m
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - result.datasource.access == 'proxy'
+ - not result.datasource.isDefault
+ - result.datasource.name == 'datasource-redis'
+ - result.datasource.orgId == 1
+ - result.datasource.type == 'redis-datasource'
+ - result.datasource.url == 'https://redisnew.company.com:6379'
+
+- name: Delete redis-datasource datasource
+ register: result
+ grafana_datasource:
+ name: datasource-redis
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- assert:
+ that:
+ - result.changed
+
+- name: Delete redis-datasource datasource (idempotency)
+ register: result
+ grafana_datasource:
+ name: datasource-redis
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- assert:
+ that:
+ - not result.changed
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/thruk.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/thruk.yml
new file mode 100644
index 000000000..3ecc92d94
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/thruk.yml
@@ -0,0 +1,78 @@
+- name: Create thruk datasource
+ register: result
+ grafana_datasource:
+ name: datasource-thruk
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: "1"
+ ds_type: sni-thruk-datasource
+ ds_url: "https://thruk.company.com/sitename/thruk"
+ tls_skip_verify: yes
+ validate_certs: no
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - "result.msg == 'Datasource datasource-thruk created'"
+
+- name: Check thruk datasource creation idempotency
+ register: result
+ grafana_datasource:
+ name: datasource-thruk
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: sni-thruk-datasource
+ ds_url: "https://thruk.company.com/sitename/thruk"
+ tls_skip_verify: yes
+ validate_certs: no
+
+- assert:
+ that:
+ - not result.changed
+ - result.datasource.basicAuth == false
+ - result.datasource.access == 'proxy'
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.jsonData.tlsAuthWithCACert == false
+ - result.datasource.name == 'datasource-thruk'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'sni-thruk-datasource'
+ - result.datasource.url == 'https://thruk.company.com/sitename/thruk'
+ - result.datasource.user == ''
+ - result.datasource.withCredentials == false
+
+- name: Delete thruk datasource
+ register: result
+ grafana_datasource:
+ name: datasource-thruk
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+
+- name: Delete thruk datasource (idempotency)
+ register: result
+ grafana_datasource:
+ name: datasource-thruk
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- assert:
+ that:
+ - not result.changed
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/uid.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/uid.yml
new file mode 100644
index 000000000..71102a074
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/uid.yml
@@ -0,0 +1,253 @@
+- name: Create datasource with uid
+ register: result
+ grafana_datasource:
+ name: datasource-with-uid
+ uid: uid1
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: prometheus
+ ds_url: https://prometheus.company.com:8086
+ basic_auth_user: "admin"
+ basic_auth_password: "admin"
+ validate_certs: False
+ is_default: no
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - "result.msg == 'Datasource datasource-with-uid created'"
+
+- name: Create datasource without uid
+ register: result
+ grafana_datasource:
+ name: datasource-without-uid
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: prometheus
+ ds_url: https://prometheus.company.com:8086
+ basic_auth_user: "admin"
+ basic_auth_password: "admin"
+ validate_certs: False
+ is_default: no
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - "result.msg == 'Datasource datasource-without-uid created'"
+
+- name: Check datasource creation idempotency with uid
+ register: result
+ grafana_datasource:
+ name: datasource-with-uid
+ uid: uid1
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: prometheus
+ ds_url: https://prometheus.company.com:8086
+ basic_auth_user: "admin"
+ basic_auth_password: "admin"
+ validate_certs: False
+ is_default: no
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
+ - result.datasource.access == 'proxy'
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.name == 'datasource-with-uid'
+ - result.datasource.uid == 'uid1'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'prometheus'
+ - result.datasource.url == 'https://prometheus.company.com:8086'
+ - result.datasource.user == ''
+ - result.datasource.withCredentials == false
+
+- name: Check datasource creation idempotency without uid
+ register: result
+ grafana_datasource:
+ name: datasource-without-uid
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: prometheus
+ ds_url: https://prometheus.company.com:8086
+ basic_auth_user: "admin"
+ basic_auth_password: "admin"
+ validate_certs: False
+ is_default: no
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
+ - result.datasource.access == 'proxy'
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.name == 'datasource-without-uid'
+ - result.datasource.uid
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'prometheus'
+ - result.datasource.url == 'https://prometheus.company.com:8086'
+ - result.datasource.user == ''
+ - result.datasource.withCredentials == false
+
+- name: Set uid for datasource with random uid
+ register: result
+ grafana_datasource:
+ name: datasource-without-uid
+ uid: uid3
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: prometheus
+ ds_url: https://prometheus.company.com:8086
+ basic_auth_user: "admin"
+ basic_auth_password: "admin"
+ validate_certs: False
+ is_default: no
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - result.datasource.access == 'proxy'
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.name == 'datasource-without-uid'
+ - result.datasource.uid == 'uid3'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'prometheus'
+ - result.datasource.url == 'https://prometheus.company.com:8086'
+ - result.datasource.user == ''
+ - result.datasource.withCredentials == false
+
+- name: Change uid for datasource
+ register: result
+ grafana_datasource:
+ name: datasource-with-uid
+ uid: uid2
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: prometheus
+ ds_url: https://prometheus.company.com:8086
+ basic_auth_user: "admin"
+ basic_auth_password: "admin"
+ validate_certs: False
+ is_default: no
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - result.datasource.access == 'proxy'
+ - result.datasource.isDefault == false
+ - result.datasource.jsonData.tlsAuth == false
+ - result.datasource.name == 'datasource-with-uid'
+ - result.datasource.uid == 'uid2'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'prometheus'
+ - result.datasource.url == 'https://prometheus.company.com:8086'
+ - result.datasource.user == ''
+ - result.datasource.withCredentials == false
+
+- name: Delete datasource-with-uid
+ register: result
+ grafana_datasource:
+ name: datasource-with-uid
+ uid: uid1
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: prometheus
+ ds_url: https://prometheus.company.com:8086
+ basic_auth_user: "admin"
+ basic_auth_password: "admin"
+ validate_certs: False
+ is_default: no
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+
+- name: Delete datasource-without-uid
+ register: result
+ grafana_datasource:
+ name: datasource-without-uid
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: prometheus
+ ds_url: https://prometheus.company.com:8086
+ basic_auth_user: "admin"
+ basic_auth_password: "admin"
+ validate_certs: False
+ is_default: no
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+
+- name: Delete datasource-with-uid (idempotency)
+ register: result
+ grafana_datasource:
+ name: datasource-with-uid
+ uid: uid1
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: prometheus
+ ds_url: https://prometheus.company.com:8086
+ basic_auth_user: "admin"
+ basic_auth_password: "admin"
+ validate_certs: False
+ is_default: no
+
+ state: absent
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/zabbix.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/zabbix.yml
new file mode 100644
index 000000000..c8a8236bf
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_datasource/tasks/zabbix.yml
@@ -0,0 +1,114 @@
+- name: Create zabbix datasource
+ register: result
+ grafana_datasource:
+ name: datasource-zabbix
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: alexanderzobnin-zabbix-datasource
+ ds_url: https://zabbix.company.com
+ zabbix_user: grafana
+ zabbix_password: '******'
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - not result.datasource.isDefault
+ - result.datasource.jsonData.username == 'grafana'
+ - result.datasource.name == 'datasource-zabbix'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'alexanderzobnin-zabbix-datasource'
+ - result.datasource.url == 'https://zabbix.company.com'
+ - result.datasource.user == ''
+ - not result.datasource.withCredentials
+ - "result.msg == 'Datasource datasource-zabbix created'"
+
+- name: Create zabbix datasource (idempotency)
+ register: result
+ grafana_datasource:
+ name: datasource-zabbix
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: alexanderzobnin-zabbix-datasource
+ ds_url: https://zabbix.company.com
+ zabbix_user: grafana
+ zabbix_password: '******'
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - not result.changed
+ - not result.datasource.isDefault
+ - result.datasource.jsonData.username == 'grafana'
+ - result.datasource.name == 'datasource-zabbix'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'alexanderzobnin-zabbix-datasource'
+ - result.datasource.url == 'https://zabbix.company.com'
+ - result.datasource.user == ''
+ - not result.datasource.withCredentials
+
+- name: Update zabbix datasource
+ register: result
+ grafana_datasource:
+ name: datasource-zabbix
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ org_id: '1'
+ ds_type: alexanderzobnin-zabbix-datasource
+ ds_url: https://zabbix.example.com
+ zabbix_user: grafana
+ zabbix_password: '******'
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed
+ - not result.datasource.isDefault
+ - result.datasource.jsonData.username == 'grafana'
+ - result.datasource.name == 'datasource-zabbix'
+ - result.datasource.orgId == 1
+ - ('password' not in result.datasource) or (result.datasource.password == '')
+ - result.datasource.type == 'alexanderzobnin-zabbix-datasource'
+ - result.datasource.url == 'https://zabbix.example.com'
+ - result.datasource.user == ''
+ - not result.datasource.withCredentials
+ - "result.msg == 'Datasource datasource-zabbix updated'"
+
+- name: Delete zabbix datasource
+ register: result
+ grafana_datasource:
+ name: datasource-zabbix
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- assert:
+ that:
+ - result.changed
+
+- name: Delete zabbix datasource (idempotency)
+ register: result
+ grafana_datasource:
+ name: datasource-zabbix
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password }}"
+ state: absent
+
+- assert:
+ that:
+ - not result.changed
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_folder/defaults/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_folder/defaults/main.yml
new file mode 100644
index 000000000..8b9c9348a
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_folder/defaults/main.yml
@@ -0,0 +1,7 @@
+---
+
+grafana_url: "http://grafana:3000/"
+grafana_username: "admin"
+grafana_password: "admin"
+
+...
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_folder/tasks/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_folder/tasks/main.yml
new file mode 100644
index 000000000..c6a520560
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_folder/tasks/main.yml
@@ -0,0 +1,55 @@
+---
+
+- name: Create a Folder
+ grafana_folder:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ title: "grafana_working_group"
+ state: present
+ register: result
+
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.folder.title == 'grafana_working_group'"
+
+- name: Test folder creation idempotency
+ grafana_folder:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ title: "grafana_working_group"
+ state: present
+ register: result
+
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.folder.title == 'grafana_working_group'"
+
+- name: Delete a Folder
+ grafana_folder:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ title: "grafana_working_group"
+ state: absent
+ register: result
+
+- assert:
+ that:
+ - "result.changed == true"
+
+- name: Test folder deletion idempotency
+ grafana_folder:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ title: "grafana_working_group"
+ state: absent
+ register: result
+
+- assert:
+ that:
+ - "result.changed == false"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/defaults/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/defaults/main.yml
new file mode 100644
index 000000000..8b9c9348a
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/defaults/main.yml
@@ -0,0 +1,7 @@
+---
+
+grafana_url: "http://grafana:3000/"
+grafana_username: "admin"
+grafana_password: "admin"
+
+...
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/dingding.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/dingding.yml
new file mode 100644
index 000000000..7279e313b
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/dingding.yml
@@ -0,0 +1,74 @@
+---
+- name: Create dingding notification channel
+ register: result
+ grafana_notification_channel:
+ uid: dingding
+ name: dingding
+ type: dingding
+ dingding_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed == True
+ - result.channel.name == "dingding"
+ - result.channel.uid == "dingding"
+ - result.channel.type == "dingding"
+
+- name: Create dingding notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: dingding
+ name: dingding
+ type: dingding
+ dingding_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed == False
+ - result.channel.name == "dingding"
+ - result.channel.uid == "dingding"
+ - result.channel.type == "dingding"
+
+- name: Delete dingding notification channel
+ register: result
+ grafana_notification_channel:
+ uid: dingding
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed == True
+
+- name: Delete dingding notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: dingding
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed == False
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/discord.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/discord.yml
new file mode 100644
index 000000000..29cfece70
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/discord.yml
@@ -0,0 +1,74 @@
+---
+- name: Create discord notification channel
+ register: result
+ grafana_notification_channel:
+ uid: discord
+ name: discord
+ type: discord
+ discord_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed == True
+ - result.channel.name == "discord"
+ - result.channel.type == "discord"
+ - result.channel.uid == "discord"
+
+- name: Create discord notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: discord
+ name: discord
+ type: discord
+ discord_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed == False
+ - result.channel.name == "discord"
+ - result.channel.type == "discord"
+ - result.channel.uid == "discord"
+
+- name: Delete discord notification channel
+ register: result
+ grafana_notification_channel:
+ uid: discord
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed == True
+
+- name: Delete discord notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: discord
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - result.changed == False
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/email.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/email.yml
new file mode 100644
index 000000000..85a236c9e
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/email.yml
@@ -0,0 +1,79 @@
+---
+- name: Create email notification channel
+ register: result
+ grafana_notification_channel:
+ uid: email
+ name: email
+ type: email
+ email_addresses:
+ - foo@example.org
+ - bar@example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "email"
+ - result.channel.type == "email"
+ - result.channel.uid == "email"
+
+- name: Create email notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: email
+ name: email
+ type: email
+ email_addresses:
+ - foo@example.org
+ - bar@example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "email"
+ - result.channel.type == "email"
+ - result.channel.uid == "email"
+
+- name: Delete discord notification channel
+ register: result
+ grafana_notification_channel:
+ uid: email
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - "result.state == 'absent'"
+
+- name: Delete discord notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: email
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/googlechat.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/googlechat.yml
new file mode 100644
index 000000000..abc7db644
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/googlechat.yml
@@ -0,0 +1,74 @@
+---
+- name: Create googlechat notification channel
+ register: result
+ grafana_notification_channel:
+ uid: googlechat
+ name: googlechat
+ type: googlechat
+ googlechat_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "googlechat"
+ - result.channel.uid == "googlechat"
+ - result.channel.type == "googlechat"
+
+- name: Create googlechat notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: googlechat
+ name: googlechat
+ type: googlechat
+ googlechat_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "googlechat"
+ - result.channel.uid == "googlechat"
+ - result.channel.type == "googlechat"
+
+- name: Delete googlechat notification channel
+ register: result
+ grafana_notification_channel:
+ uid: googlechat
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete googlechat notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: googlechat
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/hipchat.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/hipchat.yml
new file mode 100644
index 000000000..4a9ec1704
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/hipchat.yml
@@ -0,0 +1,74 @@
+---
+- name: Create hipchat notification channel
+ register: result
+ grafana_notification_channel:
+ uid: hipchat
+ name: hipchat
+ type: hipchat
+ hipchat_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "hipchat"
+ - result.channel.type == "hipchat"
+ - result.channel.uid == "hipchat"
+
+- name: Create hipchat notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: hipchat
+ name: hipchat
+ type: hipchat
+ hipchat_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "hipchat"
+ - result.channel.type == "hipchat"
+ - result.channel.uid == "hipchat"
+
+- name: Delete hipchat notification channel
+ register: result
+ grafana_notification_channel:
+ uid: hipchat
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete hipchat notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: hipchat
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/kafka.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/kafka.yml
new file mode 100644
index 000000000..ffc208acb
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/kafka.yml
@@ -0,0 +1,76 @@
+---
+- name: Create kafka notification channel
+ register: result
+ grafana_notification_channel:
+ uid: kafka
+ name: kafka
+ type: kafka
+ kafka_url: https://example.org
+ kafka_topic: test
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "kafka"
+ - result.channel.uid == "kafka"
+ - result.channel.type == "kafka"
+
+- name: Create kafka notification channel (idempotentcy)
+ register: result
+ grafana_notification_channel:
+ uid: kafka
+ name: kafka
+ type: kafka
+ kafka_url: https://example.org
+ kafka_topic: test
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "kafka"
+ - result.channel.uid == "kafka"
+ - result.channel.type == "kafka"
+
+- name: Delete kafka notification channel
+ register: result
+ grafana_notification_channel:
+ uid: kafka
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete kafka notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: kafka
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/line.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/line.yml
new file mode 100644
index 000000000..83a1863ba
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/line.yml
@@ -0,0 +1,74 @@
+---
+- name: Create line notification channel
+ register: result
+ grafana_notification_channel:
+ uid: line
+ name: line
+ type: line
+ line_token: xxx
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.uid == "line"
+ - result.channel.name == "line"
+ - result.channel.type == "line"
+
+- name: Create line notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: line
+ name: line
+ type: line
+ line_token: xxx
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.uid == "line"
+ - result.channel.name == "line"
+ - result.channel.type == "line"
+
+- name: Delete line notification channel
+ register: result
+ grafana_notification_channel:
+ uid: line
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete line notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: line
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/main.yml
new file mode 100644
index 000000000..ada6338c7
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/main.yml
@@ -0,0 +1,20 @@
+---
+- block:
+ - include: dingding.yml
+ - include: discord.yml
+ - include: email.yml
+ - include: googlechat.yml
+ - include: hipchat.yml
+ - include: kafka.yml
+# - include: line.yml
+ - include: teams.yml
+ - include: opsgenie.yml
+ - include: pagerduty.yml
+ - include: prometheus.yml
+ - include: pushover.yml
+ - include: sensu.yml
+ - include: slack-and-beyond.yml
+ - include: telegram.yml
+# - include: threema.yml
+ - include: victorops.yml
+ - include: webhook.yml
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/opsgenie.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/opsgenie.yml
new file mode 100644
index 000000000..f871fe719
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/opsgenie.yml
@@ -0,0 +1,77 @@
+---
+- name: Create opsgenie notification channel
+ register: result
+ grafana_notification_channel:
+ uid: opsgenie
+ name: opsgenie
+ type: opsgenie
+ opsgenie_url: https://example.org
+ opsgenie_api_key: xxx
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "opsgenie"
+ - result.channel.type == "opsgenie"
+ - result.channel.uid == "opsgenie"
+
+- name: Create opsgenie notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: opsgenie
+ name: opsgenie
+ type: opsgenie
+ opsgenie_url: https://example.org
+ opsgenie_api_key: xxx
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "opsgenie"
+ - result.channel.type == "opsgenie"
+ - result.channel.uid == "opsgenie"
+
+- name: Delete opsgenie notification channel
+ register: result
+ grafana_notification_channel:
+ uid: opsgenie
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - "result.state == 'absent'"
+
+- name: Delete opsgenie notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: opsgenie
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/pagerduty.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/pagerduty.yml
new file mode 100644
index 000000000..a8fa940b0
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/pagerduty.yml
@@ -0,0 +1,74 @@
+---
+- name: Create pagerduty notification channel
+ register: result
+ grafana_notification_channel:
+ uid: pagerduty
+ name: pagerduty
+ type: pagerduty
+ pagerduty_integration_key: xxx
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "pagerduty"
+ - result.channel.type == "pagerduty"
+ - result.channel.uid == "pagerduty"
+
+- name: Create pagerduty notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: pagerduty
+ name: pagerduty
+ type: pagerduty
+ pagerduty_integration_key: xxx
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "pagerduty"
+ - result.channel.type == "pagerduty"
+ - result.channel.uid == "pagerduty"
+
+- name: Delete pagerduty notification channel
+ register: result
+ grafana_notification_channel:
+ uid: pagerduty
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete pagerduty notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: pagerduty
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/prometheus.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/prometheus.yml
new file mode 100644
index 000000000..40810eaf3
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/prometheus.yml
@@ -0,0 +1,74 @@
+---
+- name: Create prometheus notification channel
+ register: result
+ grafana_notification_channel:
+ uid: prometheus
+ name: prometheus
+ type: prometheus
+ prometheus_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "prometheus"
+ - result.channel.uid == "prometheus"
+ - result.channel.type == "prometheus-alertmanager"
+
+- name: Create prometheus notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: prometheus
+ name: prometheus
+ type: prometheus
+ prometheus_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "prometheus"
+ - result.channel.uid == "prometheus"
+ - result.channel.type == "prometheus-alertmanager"
+
+- name: Delete prometheus notification channel
+ register: result
+ grafana_notification_channel:
+ uid: prometheus
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete prometheus notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: prometheus
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/pushover.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/pushover.yml
new file mode 100644
index 000000000..894bd71e6
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/pushover.yml
@@ -0,0 +1,76 @@
+---
+- name: Create pushover notification channel
+ register: result
+ grafana_notification_channel:
+ uid: pushover
+ name: pushover
+ type: pushover
+ pushover_api_token: xxx
+ pushover_user_key: yyy
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "pushover"
+ - result.channel.uid == "pushover"
+ - result.channel.type == "pushover"
+
+- name: Create pushover notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: pushover
+ name: pushover
+ type: pushover
+ pushover_api_token: xxx
+ pushover_user_key: yyy
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "pushover"
+ - result.channel.uid == "pushover"
+ - result.channel.type == "pushover"
+
+- name: Delete pushover notification channel
+ register: result
+ grafana_notification_channel:
+ uid: pushover
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete pushover notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: pushover
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/sensu.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/sensu.yml
new file mode 100644
index 000000000..01619b719
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/sensu.yml
@@ -0,0 +1,74 @@
+---
+- name: Create sensu notification channel
+ register: result
+ grafana_notification_channel:
+ uid: sensu
+ name: sensu
+ type: sensu
+ sensu_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "sensu"
+ - result.channel.type == "sensu"
+ - result.channel.uid == "sensu"
+
+- name: Create sensu notification channel
+ register: result
+ grafana_notification_channel:
+ uid: sensu
+ name: sensu
+ type: sensu
+ sensu_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "sensu"
+ - result.channel.type == "sensu"
+ - result.channel.uid == "sensu"
+
+- name: Delete sensu notification channel
+ register: result
+ grafana_notification_channel:
+ uid: sensu
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete sensu notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: sensu
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/slack-and-beyond.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/slack-and-beyond.yml
new file mode 100644
index 000000000..0748c8bdb
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/slack-and-beyond.yml
@@ -0,0 +1,110 @@
+---
+- name: Create slack notification channel
+ register: result
+ grafana_notification_channel:
+ uid: slack
+ name: slack
+ type: slack
+ slack_url: https://hooks.slack.com/services/xxx/yyy/zzz
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "slack"
+ - result.channel.type == "slack"
+ - result.channel.uid == "slack"
+
+- name: Create slack notification channel
+ register: result
+ grafana_notification_channel:
+ uid: slack
+ name: slack
+ type: slack
+ slack_url: https://hooks.slack.com/services/xxx/yyy/zzz
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "slack"
+ - result.channel.type == "slack"
+ - result.channel.uid == "slack"
+
+- name: Check slack notification channel idempotency
+ register: result
+ grafana_notification_channel:
+ uid: slack
+ name: slack
+ type: slack
+ slack_url: https://hooks.slack.com/services/xxx/yyy/zzz
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+
+- name: Update slack notification channel
+ register: result
+ grafana_notification_channel:
+ uid: slack
+ name: slack
+ type: slack
+ slack_url: https://hooks.slack.com/services/xxx/yyy/fff
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete slack notification channel
+ register: result
+ grafana_notification_channel:
+ state: absent
+ uid: slack
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete slack notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ state: absent
+ uid: slack
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/teams.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/teams.yml
new file mode 100644
index 000000000..cfc44aef3
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/teams.yml
@@ -0,0 +1,74 @@
+---
+- name: Create teams notification channel
+ register: result
+ grafana_notification_channel:
+ uid: teams
+ name: teams
+ type: teams
+ teams_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "teams"
+ - result.channel.uid == "teams"
+ - result.channel.type == "teams"
+
+- name: Create teams notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: teams
+ name: teams
+ type: teams
+ teams_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "teams"
+ - result.channel.uid == "teams"
+ - result.channel.type == "teams"
+
+- name: Delete teams notification channel
+ register: result
+ grafana_notification_channel:
+ uid: teams
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete teams notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: teams
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/telegram.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/telegram.yml
new file mode 100644
index 000000000..98a7a3c6d
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/telegram.yml
@@ -0,0 +1,76 @@
+---
+- name: Create telegram notification channel
+ register: result
+ grafana_notification_channel:
+ uid: telegram
+ name: telegram
+ type: telegram
+ telegram_bot_token: xxx
+ telegram_chat_id: yyy
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "telegram"
+ - result.channel.type == "telegram"
+ - result.channel.uid == "telegram"
+
+- name: Create telegram notification channel
+ register: result
+ grafana_notification_channel:
+ uid: telegram
+ name: telegram
+ type: telegram
+ telegram_bot_token: xxx
+ telegram_chat_id: yyy
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "telegram"
+ - result.channel.type == "telegram"
+ - result.channel.uid == "telegram"
+
+- name: Delete telegram notification channel
+ register: result
+ grafana_notification_channel:
+ uid: telegram
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete telegram notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: telegram
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/threema.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/threema.yml
new file mode 100644
index 000000000..7858b6977
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/threema.yml
@@ -0,0 +1,78 @@
+---
+- name: Create threema notification channel
+ register: result
+ grafana_notification_channel:
+ uid: threema
+ name: threema
+ type: threema
+ threema_gateway_id: "*xxxxxxx"
+ threema_recipient_id: yyyyyyyy
+ threema_api_secret: zzz
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "threema"
+ - result.channel.type == "threema"
+ - result.channel.uid == "threema"
+
+- name: Create threema notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: threema
+ name: threema
+ type: threema
+ threema_gateway_id: xxx
+ threema_recepient_id: yyy
+ threema_api_secret: zzz
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "threema"
+ - result.channel.type == "threema"
+ - result.channel.uid == "threema"
+
+- name: Delete threema notification channel
+ register: result
+ grafana_notification_channel:
+ uid: threema
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete threema notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: threema
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/victorops.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/victorops.yml
new file mode 100644
index 000000000..3779e813a
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/victorops.yml
@@ -0,0 +1,74 @@
+---
+- name: Create victorops notification channel
+ register: result
+ grafana_notification_channel:
+ uid: victorops
+ name: victorops
+ type: victorops
+ victorops_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "victorops"
+ - result.channel.type == "victorops"
+ - result.channel.uid == "victorops"
+
+- name: Create victorops notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: victorops
+ name: victorops
+ type: victorops
+ victorops_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "victorops"
+ - result.channel.type == "victorops"
+ - result.channel.uid == "victorops"
+
+- name: Delete victorops notification channel
+ register: result
+ grafana_notification_channel:
+ uid: victorops
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete victorops notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: victorops
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/webhook.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/webhook.yml
new file mode 100644
index 000000000..c9efd9193
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_notification_channel/tasks/webhook.yml
@@ -0,0 +1,74 @@
+---
+- name: Create webhook notification channel
+ register: result
+ grafana_notification_channel:
+ uid: webhook
+ name: webhook
+ type: webhook
+ webhook_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+ - result.channel.name == "webhook"
+ - result.channel.uid == "webhook"
+ - result.channel.type == "webhook"
+
+- name: Create webhook notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: webhook
+ name: webhook
+ type: webhook
+ webhook_url: https://example.org
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
+ - result.channel.name == "webhook"
+ - result.channel.uid == "webhook"
+ - result.channel.type == "webhook"
+
+- name: Delete webhook notification channel
+ register: result
+ grafana_notification_channel:
+ uid: webhook
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == True"
+
+- name: Delete webhook notification channel (idempotency)
+ register: result
+ grafana_notification_channel:
+ uid: webhook
+ state: absent
+ grafana_url: "{{ grafana_url }}"
+ grafana_user: "{{ grafana_username }}"
+ grafana_password: "{{ grafana_password}}"
+
+- debug:
+ var: result
+
+- assert:
+ that:
+ - "result.changed == False"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_organization/defaults/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_organization/defaults/main.yml
new file mode 100644
index 000000000..7bb77ea3f
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_organization/defaults/main.yml
@@ -0,0 +1,4 @@
+---
+grafana_url: "http://grafana:3000/"
+grafana_username: "admin"
+grafana_password: "admin"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_organization/tasks/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_organization/tasks/main.yml
new file mode 100644
index 000000000..f8ccdf3bf
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_organization/tasks/main.yml
@@ -0,0 +1,57 @@
+---
+
+- name: Create a Grafana organization
+ community.grafana.grafana_organization:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: orgtest
+ state: present
+ register: result
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.failed == false"
+ - "result.org.name == 'orgtest'"
+
+- name: check idempotency Grafana organization
+ community.grafana.grafana_organization:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: orgtest
+ state: present
+ register: result
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.failed == false"
+ - "result.org.name == 'orgtest'"
+
+- name: Delete a Grafana organization
+ community.grafana.grafana_organization:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: orgtest
+ state: absent
+ register: result
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.failed == false"
+ - "result.msg |length > 0"
+
+- name: check idempotency delete a Grafana organization
+ community.grafana.grafana_organization:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: orgtest
+ state: absent
+ register: result
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.failed == false"
+ - "result.msg == 'No org found, nothing to do'"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_team/defaults/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_team/defaults/main.yml
new file mode 100644
index 000000000..8b9c9348a
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_team/defaults/main.yml
@@ -0,0 +1,7 @@
+---
+
+grafana_url: "http://grafana:3000/"
+grafana_username: "admin"
+grafana_password: "admin"
+
+...
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_team/tasks/create_user.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_team/tasks/create_user.yml
new file mode 100644
index 000000000..6971d07b6
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_team/tasks/create_user.yml
@@ -0,0 +1,29 @@
+- name: Create John Doe for tests purpose through uri module
+ uri:
+ url: "{{ grafana_url }}api/admin/users"
+ method: POST
+ user: "{{ grafana_username }}"
+ password: "{{ grafana_password }}"
+ force_basic_auth: yes
+ body:
+ name: "John"
+ email: "john+doe@example.com"
+ login: "john"
+ password: "userpassword"
+ body_format: json
+ status_code: 200
+
+- name: Create Jane Doe for tests purpose through uri module
+ uri:
+ url: "{{ grafana_url }}api/admin/users"
+ method: POST
+ user: "{{ grafana_username }}"
+ password: "{{ grafana_password }}"
+ force_basic_auth: yes
+ body:
+ name: "Jane"
+ email: "jane.doe@example.com"
+ login: "jane"
+ password: "userpassword"
+ body_format: json
+ status_code: 200
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_team/tasks/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_team/tasks/main.yml
new file mode 100644
index 000000000..2d74581b7
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_team/tasks/main.yml
@@ -0,0 +1,187 @@
+---
+
+- name: Create a Team
+ grafana_team:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "grafana_working_group"
+ email: "foo.bar@example.com"
+ state: present
+ register: result
+
+- set_fact:
+ # From Grafana 9.0.0, the API user automatically becomes a member of the team
+ auto_member: "{{ result.team.memberCount == 1 }}"
+
+- set_fact:
+ expected_members: "{{ auto_member | ternary(['********@localhost'], []) }}"
+
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.team.name == 'grafana_working_group'"
+ - "result.team.email == 'foo.bar@example.com'"
+ - "result.team.memberCount == (expected_members|length)"
+ - "result.team.members == expected_members"
+
+- name: Check idempotency on team creation
+ grafana_team:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "grafana_working_group"
+ email: "foo.bar@example.com"
+ state: present
+ register: result
+
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.team.name == 'grafana_working_group'"
+ - "result.team.email == 'foo.bar@example.com'"
+ - "result.team.memberCount == (expected_members|length)"
+ - "result.team.members == expected_members"
+
+- name: Check a team can be deleted
+ grafana_team:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "grafana_working_group"
+ email: "foo.bar@example.com"
+ state: absent
+ register: result
+
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.message == 'Team deleted'"
+
+- name: Check idempotency on team deletion
+ grafana_team:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "grafana_working_group"
+ email: "foo.bar@example.com"
+ state: absent
+ register: result
+
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.message == 'No team found'"
+
+- name: Create users for tests purpose
+ import_tasks: create_user.yml
+
+- name: Create a Team with members
+ grafana_team:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "grafana_working_group"
+ email: "foo.bar@example.com"
+ members:
+ - "john+doe@example.com"
+ - "jane.doe@example.com"
+ state: present
+ register: result
+
+- set_fact:
+ expected_members: "{{ auto_member | ternary(['********@localhost', 'jane.doe@example.com', 'john+doe@example.com'], ['jane.doe@example.com', 'john+doe@example.com']) }}"
+
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.team.name == 'grafana_working_group'"
+ - "result.team.email == 'foo.bar@example.com'"
+ - "result.team.memberCount == (expected_members|length)"
+ - "result.team.members == expected_members"
+
+- name: Ensure a Team exists with member not enforced
+ grafana_team:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "grafana_working_group"
+ email: "foo.bar@example.com"
+ members:
+ - "john+doe@example.com"
+ state: present
+ register: result
+
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.team.name == 'grafana_working_group'"
+ - "result.team.email == 'foo.bar@example.com'"
+ - "result.team.memberCount == (expected_members|length)"
+ - "result.team.members == expected_members"
+
+- set_fact:
+ enforced_members: "{{ auto_member | ternary(['admin@localhost', 'john+doe@example.com'], ['john+doe@example.com']) }}"
+ expected_members: "{{ auto_member | ternary(['********@localhost', 'john+doe@example.com'], ['john+doe@example.com']) }}"
+
+- name: Ensure a Team exists with member enforced
+ grafana_team:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "grafana_working_group"
+ email: "foo.bar@example.com"
+ members: "{{ enforced_members }}"
+ enforce_members: true
+ state: present
+ register: result
+
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.team.name == 'grafana_working_group'"
+ - "result.team.email == 'foo.bar@example.com'"
+ - "result.team.memberCount == (expected_members|length)"
+ - "result.team.members == expected_members"
+
+- name: Ensure a Team exists with members omitted
+ grafana_team:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "grafana_working_group"
+ email: "foo.bar@example.com"
+ state: present
+ register: result
+
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.team.name == 'grafana_working_group'"
+ - "result.team.email == 'foo.bar@example.com'"
+ - "result.team.memberCount == (expected_members|length)"
+ - "result.team.members == expected_members"
+
+- name: Add new member to existing Team
+ grafana_team:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "grafana_working_group"
+ email: "foo.bar@example.com"
+ members:
+ - "john+doe@example.com"
+ - "jane.doe@example.com"
+ state: present
+ register: result
+
+- set_fact:
+ expected_members: "{{ auto_member | ternary(['********@localhost', 'jane.doe@example.com', 'john+doe@example.com'], ['jane.doe@example.com', 'john+doe@example.com']) }}"
+
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.team.name == 'grafana_working_group'"
+ - "result.team.email == 'foo.bar@example.com'"
+ - "result.team.memberCount == (expected_members|length)"
+ - "result.team.members == expected_members"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_user/defaults/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_user/defaults/main.yml
new file mode 100644
index 000000000..7bb77ea3f
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_user/defaults/main.yml
@@ -0,0 +1,4 @@
+---
+grafana_url: "http://grafana:3000/"
+grafana_username: "admin"
+grafana_password: "admin"
diff --git a/ansible_collections/community/grafana/tests/integration/targets/grafana_user/tasks/main.yml b/ansible_collections/community/grafana/tests/integration/targets/grafana_user/tasks/main.yml
new file mode 100644
index 000000000..c62801653
--- /dev/null
+++ b/ansible_collections/community/grafana/tests/integration/targets/grafana_user/tasks/main.yml
@@ -0,0 +1,237 @@
+---
+- name: Create new admin
+ grafana_user:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "Harley Quinn"
+ email: harley.quinn@gotham.city
+ login: harley
+ password: Wy3ta6ob6M3wHELv58MPfqOe126RTnWpcYfEhyJm
+ is_admin: true
+ state: present
+ register: result
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.failed == false"
+ - "result.user.name == 'Harley Quinn'"
+ - "result.user.email == 'harley.quinn@gotham.city'"
+ - "result.user.isGrafanaAdmin == true"
+
+- name: Check idempotency on admin creation
+ grafana_user:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "Harley Quinn"
+ email: harley.quinn@gotham.city
+ login: harley
+ password: Wy3ta6ob6M3wHELv58MPfqOe126RTnWpcYfEhyJm
+ is_admin: true
+ state: present
+ register: result
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.user.name == 'Harley Quinn'"
+ - "result.user.email == 'harley.quinn@gotham.city'"
+ - "result.user.isGrafanaAdmin == true"
+
+- name: Check user creation with Grafana API
+ uri:
+ url: "{{ grafana_url }}api/users/lookup?loginOrEmail=harley"
+ user: "{{ grafana_username }}"
+ password: "{{ grafana_password }}"
+ force_basic_auth: yes
+ status_code: 200
+ headers:
+ Accept: application/json
+ Content-Type: application/json
+ register: result
+- assert:
+ that:
+ - "result.json.name == 'Harley Quinn'"
+ - "result.json.email == 'harley.quinn@gotham.city'"
+ - "result.json.isGrafanaAdmin == true"
+
+- name: Create a Grafana user without password (expect failure)
+ grafana_user:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "Bruce Wayne"
+ email: batman@gotham.city
+ login: batman
+ state: present
+ register: result
+ ignore_errors: yes
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.failed == true"
+ - "result.msg == 'missing required arguments: password'"
+
+- name: Create a Grafana user
+ grafana_user:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "Bruce Wayne"
+ email: batman@gotham.city
+ login: batman
+ password: robin
+ state: present
+ register: result
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.user.name == 'Bruce Wayne'"
+ - "result.user.email == 'batman@gotham.city'"
+ - "result.user.isGrafanaAdmin == false"
+
+- name: Check idempotency on user creation (password not requiered)
+ grafana_user:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "Bruce Wayne"
+ email: batman@gotham.city
+ login: batman
+ state: present
+ register: result
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.user.name == 'Bruce Wayne'"
+ - "result.user.email == 'batman@gotham.city'"
+ - "result.user.isGrafanaAdmin == false"
+
+- name: Check user creation with Grafana API
+ uri:
+ url: "{{ grafana_url }}api/users/lookup?loginOrEmail=batman"
+ user: "{{ grafana_username }}"
+ password: "{{ grafana_password }}"
+ force_basic_auth: yes
+ status_code: 200
+ headers:
+ Accept: application/json
+ Content-Type: application/json
+ register: result
+- assert:
+ that:
+ - "result.json.name == 'Bruce Wayne'"
+ - "result.json.email == 'batman@gotham.city'"
+ - "result.json.isGrafanaAdmin == false"
+
+- name: Update Grafana user
+ grafana_user:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "The Dark Knight"
+ email: thedarkknight@gotham.city
+ login: batman
+ password: robin
+ is_admin: true
+ state: present
+ register: result
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.user.name == 'The Dark Knight'"
+ - "result.user.email == 'thedarkknight@gotham.city'"
+ - "result.user.isGrafanaAdmin == true"
+
+- name: Check user update with Grafana API
+ uri:
+ url: "{{ grafana_url }}api/users/lookup?loginOrEmail=batman"
+ user: "{{ grafana_username }}"
+ password: "{{ grafana_password }}"
+ force_basic_auth: yes
+ status_code: 200
+ headers:
+ Accept: application/json
+ Content-Type: application/json
+ register: result
+- assert:
+ that:
+ - "result.json.name == 'The Dark Knight'"
+ - "result.json.email == 'thedarkknight@gotham.city'"
+ - "result.json.isGrafanaAdmin == true"
+
+- name: Delete a Grafana user
+ grafana_user:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ login: batman
+ state: absent
+ register: result
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.message == 'User deleted'"
+
+- name: Check idempotency on user deletion
+ grafana_user:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ login: batman
+ state: absent
+ register: result
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.message == 'No user found, nothing to do'"
+
+- name: Check user deletion with Grafana API (expect 404 Not Found)
+ uri:
+ url: "{{ grafana_url }}api/users/lookup?loginOrEmail=batman"
+ user: "{{ grafana_username }}"
+ password: "{{ grafana_password }}"
+ force_basic_auth: yes
+ status_code: 404
+ headers:
+ Accept: application/json
+ Content-Type: application/json
+ register: result
+- assert:
+ that:
+ - "result.json.message | lower == 'user not found'"
+
+- name: Create a Grafana user with character encoding
+ grafana_user:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "Bruce Wayne"
+ email: bruce+wayne@gotham.city
+ login: bruce+wayne@gotham.city
+ password: robin
+ state: present
+ register: result
+- assert:
+ that:
+ - "result.changed == true"
+ - "result.user.name == 'Bruce Wayne'"
+ - "result.user.email == 'bruce+wayne@gotham.city'"
+ - "result.user.isGrafanaAdmin == false"
+
+- name: Check idempotency on user creation (password not requiered)
+ grafana_user:
+ url: "{{ grafana_url }}"
+ url_username: "{{ grafana_username }}"
+ url_password: "{{ grafana_password }}"
+ name: "Bruce Wayne"
+ email: bruce+wayne@gotham.city
+ login: bruce+wayne@gotham.city
+ state: present
+ register: result
+- assert:
+ that:
+ - "result.changed == false"
+ - "result.user.name == 'Bruce Wayne'"
+ - "result.user.email == 'bruce+wayne@gotham.city'"
+ - "result.user.isGrafanaAdmin == false"