From 14b9006a28f6ff497358c472e552e85e8781e42e Mon Sep 17 00:00:00 2001 From: Gene Liverman Date: Thu, 3 Jan 2019 16:43:38 -0500 Subject: [PATCH] Add a task for setting the admin user's password This task will allow you to change the admin user's password without having to remember the curl command for the Grafana API. --- README.md | 15 ++++++++++++++ tasks/change_grafana_admin_password.json | 25 ++++++++++++++++++++++++ tasks/change_grafana_admin_password.sh | 9 +++++++++ 3 files changed, 49 insertions(+) create mode 100644 tasks/change_grafana_admin_password.json create mode 100644 tasks/change_grafana_admin_password.sh diff --git a/README.md b/README.md index bdec5685a..5ca0d0141 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ 1. [Usage](#usage) * [Classes and Defined Types](#classes-and-defined-types) * [Advanced usage](#advanced-usage) +1. [Tasks](#tasks) 1. [Limitations](#limitations) 1. [Copyright and License](#copyright-and-license) @@ -864,6 +865,20 @@ the filesystem of the puppetserver/master. Thus you may specify a local directory with grafana dashboards you wish to provision into grafana. +## Tasks + +### `change_grafana_admin_password` + +`old_password`: the old admin password + +`new_password`: the password you want to use for the admin user + +`uri`: `http` or `https` + +`port`: the port Grafana runs on locally + +This task can be used to change the password for the admin user in grafana + ## Limitations This module has been tested on Ubuntu 14.04, using each of the 'archive', 'docker' diff --git a/tasks/change_grafana_admin_password.json b/tasks/change_grafana_admin_password.json new file mode 100644 index 000000000..720bd97d2 --- /dev/null +++ b/tasks/change_grafana_admin_password.json @@ -0,0 +1,25 @@ +{ + "puppet_task_version": 1, + "supports_noop": false, + "description": "Change the Grafana admin user's password", + "parameters": { + "old_password": { + "description": "The old admin password", + "type": "Optional[String[1]]", + "sensitive": true + }, + "new_password": { + "description": "The new admin password", + "type": "Optional[String[1]]", + "sensitive": true + }, + "uri": { + "description": "http or https", + "type": "Enum['http','https']" + }, + "port": { + "description": "The port Grafana is running on", + "type": "Integer" + } + } +} \ No newline at end of file diff --git a/tasks/change_grafana_admin_password.sh b/tasks/change_grafana_admin_password.sh new file mode 100644 index 000000000..38465e4fe --- /dev/null +++ b/tasks/change_grafana_admin_password.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +payload="{ + \"oldPassword\": \"$PT_old_password\", + \"newPassword\": \"$PT_new_password\", + \"confirmNew\": \"$PT_new_password\" +}" + +cmd="/usr/bin/curl -X PUT -H 'Content-Type: application/json' -d '$payload' '$PT_uri://admin:$PT_old_password@localhost:$PT_port/api/user/password'" +eval "$cmd"