summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Matysek <eric.matysek@gmail.com>2018-11-09 17:27:11 -0500
committerToshio Kuratomi <a.badger@gmail.com>2018-11-12 19:22:43 -0800
commit483226cdceaeb306e78dde57158061723ec8c1dd (patch)
tree7d827890b8c34e7b3e9dbeeb6474a47d89d2a0d3
parent1abd90e3e682f2c5fb7a2d44d1c5a48820ded603 (diff)
downloadansible-483226cdceaeb306e78dde57158061723ec8c1dd.tar.gz
Fix consistency issue in grafana_dashboard module. (#47459)
* Move check for 'dashboard' key to before the create/update if statement. * Add changelog fragment for PR #47459 (cherry picked from commit 880762e07ecf313caa8844260e4b37054848ca2d)
-rw-r--r--changelogs/fragments/47459_grafana_dashboard_consistency_fix.yaml2
-rw-r--r--lib/ansible/modules/monitoring/grafana_dashboard.py6
2 files changed, 6 insertions, 2 deletions
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 a07d33b916..4b4ae9bacc 100644
--- a/lib/ansible/modules/monitoring/grafana_dashboard.py
+++ b/lib/ansible/modules/monitoring/grafana_dashboard.py
@@ -226,6 +226,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)
@@ -278,8 +282,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