From 159f61ac266ed02b24c5a1bea6d692eef471bf41 Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Wed, 11 Dec 2024 20:50:03 +0000 Subject: [PATCH] fixup! fixup! fixup! fixup! fixup! fixup! Allow managing dashboards in subfolders --- changelogs/fragments/411-dashboard-subfolders.yml | 4 ++++ plugins/modules/grafana_dashboard.py | 5 +++++ roles/grafana/README.md | 1 + .../grafana_dashboard/tasks/dashboard-folder-destination.yml | 5 +++++ 4 files changed, 15 insertions(+) create mode 100644 changelogs/fragments/411-dashboard-subfolders.yml diff --git a/changelogs/fragments/411-dashboard-subfolders.yml b/changelogs/fragments/411-dashboard-subfolders.yml new file mode 100644 index 00000000..8f674a56 --- /dev/null +++ b/changelogs/fragments/411-dashboard-subfolders.yml @@ -0,0 +1,4 @@ + +--- +minor_changes: + - Allow creating dashboards in subfolders for `grafana_dashboard` diff --git a/plugins/modules/grafana_dashboard.py b/plugins/modules/grafana_dashboard.py index 0474655d..335f34c9 100644 --- a/plugins/modules/grafana_dashboard.py +++ b/plugins/modules/grafana_dashboard.py @@ -400,6 +400,11 @@ def grafana_create_dashboard(module, data): # test if the folder exists folder_exists = False + if data["parent_uid"] and grafana_version < 11: + module.fail_json( + failed=True, msg="Subfolder API is available starting Grafana v11" + ) + if grafana_version >= 5: folder_exists, folder_id = grafana_folder_exists( module, data["url"], data["folder"], data["parent_uid"], headers diff --git a/roles/grafana/README.md b/roles/grafana/README.md index 5c76497c..5ccfa5a6 100644 --- a/roles/grafana/README.md +++ b/roles/grafana/README.md @@ -87,6 +87,7 @@ Configure Grafana organizations, dashboards, folders, datasources, teams and use | org_id | no | | org_name | no | | overwrite | no | +| parent_uid | no | | path | no | | slug | no | | state | no | diff --git a/tests/integration/targets/grafana_dashboard/tasks/dashboard-folder-destination.yml b/tests/integration/targets/grafana_dashboard/tasks/dashboard-folder-destination.yml index 02c39e39..f426eeff 100644 --- a/tests/integration/targets/grafana_dashboard/tasks/dashboard-folder-destination.yml +++ b/tests/integration/targets/grafana_dashboard/tasks/dashboard-folder-destination.yml @@ -96,3 +96,8 @@ that: - diff_result4.failed == false - diff_result4.changed == true + rescue: + - name: Skip if we are running an older version of Grafana + ansible.builtin.assert: + that: + - sub_folder.msg | default ('') == 'Subfolder API is available'