Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding users from list #14

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ grafana_protocol: http
grafana_http_addr: 0.0.0.0 # The ip address to bind to
grafana_http_port: 3000 # The http port to use
grafana_domain: localhost # The public facing domain name used to access grafana from a browser
grafana_api_base_url: "http://{{ grafana_domain }}"
grafana_enforce_domain: false
grafana_root_url: "%(protocol)s://%(domain)s:%(http_port)s/"
grafana_router_logging: false # Log web requests
Expand Down Expand Up @@ -159,6 +160,9 @@ grafana_nginx_ssl_key: ""
grafana_nginx_ssl_redirect: "{{grafana_nginx_ssl}}"
grafana_nginx_port: 80

# Grafana users (add using api)
grafana_users: [] # list of dict with format: {username: 'user1', password: 'pass1'}

```

#### Usage
Expand Down
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ grafana_protocol: http
grafana_http_addr: 0.0.0.0 # The ip address to bind to
grafana_http_port: 3000 # The http port to use
grafana_domain: localhost # The public facing domain name used to access grafana from a browser
grafana_api_base_url: "http://{{ grafana_domain }}"
grafana_enforce_domain: false
grafana_root_url: "%(protocol)s://%(domain)s:%(http_port)s/"
grafana_router_logging: false # Log web requests
Expand Down Expand Up @@ -145,4 +146,7 @@ grafana_nginx_ssl_key: ""
grafana_nginx_ssl_redirect: "{{grafana_nginx_ssl}}"
grafana_nginx_port: 80

# Grafana users (add using api)
grafana_users: [] # list of dict with format: {username: 'user1', password: 'pass1'}

# vim:sw=2
4 changes: 4 additions & 0 deletions tasks/grafana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@

- include: configure.yml
tags: [grafana, grafana-configure]

- include: users.yml
tags: [grafana, grafana-users]
when: grafana_users|length > 0
21 changes: 21 additions & 0 deletions tasks/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---

# if admin user is set up in this run, we depend on application run with recent config
- meta: flush_handlers

- name: Add users using API
uri:
url: "{{ grafana_api_base_url }}/api/admin/users"
method: POST
body_format: json
# can't use api-key for this at the moment: http://docs.grafana.org/http_api/admin/
force_basic_auth: true
user: "{{ grafana_admin_user }}"
password: "{{ grafana_admin_password }}"
body:
name: "{{ item.username }}"
#email: "{{ item.username }}@domain" # not mandatory, users will have email = name in this case
login: "{{ item.username }}"
password: "{{ item.password }}"
status_code: 200,500 # existing users are not checked, inserting existing user causing 500 internal server error
with_items: "{{ grafana_users }}"
2 changes: 2 additions & 0 deletions templates/grafana.ini.j2
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ google_analytics_ua_id = {{ grafana_google_analytics_ua_id }}

#################################### Security ####################################
[security]
{% if grafana_admin_user and grafana_admin_password %}
# default admin user, created on startup
admin_user = {{ grafana_admin_user }}

# default admin password, can be changed before first start of grafana, or in profile settings
admin_password = {{ grafana_admin_password }}

{% endif %}
# used for signing
secret_key = {{ grafana_secret_key }}

Expand Down