diff --git a/changelogs/fragments/47459_grafana_dashboard_consistency_fix.yaml b/changelogs/fragments/47459_grafana_dashboard_consistency_fix.yaml new file mode 100644 index 0000000000..6bc7216cb0 --- /dev/null +++ b/changelogs/fragments/47459_grafana_dashboard_consistency_fix.yaml @@ -0,0 +1,2 @@ +bugfixes: + - Fix consistency issue in grafana_dashboard module where the module would detect absence of 'dashboard' key on dashboard create but not dashboard update. \ No newline at end of file diff --git a/lib/ansible/modules/monitoring/grafana_dashboard.py b/lib/ansible/modules/monitoring/grafana_dashboard.py index cb1aa51af8..e974d865d4 100644 --- a/lib/ansible/modules/monitoring/grafana_dashboard.py +++ b/lib/ansible/modules/monitoring/grafana_dashboard.py @@ -225,6 +225,10 @@ def grafana_create_dashboard(module, data): except Exception as e: raise GrafanaAPIException("Can't load json file %s" % to_native(e)) + # Check that the dashboard JSON is nested under the 'dashboard' key + if 'dashboard' not in payload: + payload = {'dashboard': payload} + # define http header headers = grafana_headers(module, data) @@ -277,8 +281,6 @@ def grafana_create_dashboard(module, data): raise GrafanaAPIException('Unable to update the dashboard %s : %s' % (uid, body['message'])) else: # create - if 'dashboard' not in payload: - payload = {'dashboard': payload} r, info = fetch_url(module, '%s/api/dashboards/db' % data['grafana_url'], data=json.dumps(payload), headers=headers, method='POST') if info['status'] == 200: result['msg'] = "Dashboard %s created" % uid