Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
Ensure initial admin password is set on first run
Browse files Browse the repository at this point in the history
This change applies only to the debian-based family.

After package install, grafana-server service is automatically started.
In result, default "admin" password is assigned to "admin" user.

Reference: http://docs.grafana.org/installation/configuration/#admin-password

To setup initial password it is required to write it in grafana.ini
before first service start. Currently, the only way to achieve this, is
to block service autostart (dpkg_autostart resource) and let Chef
handle everything - enable service and restart after grafana.ini is
changed.

This change should not be disruptive for any cookbook user.
  • Loading branch information
szymonpk committed Nov 2, 2017
1 parent 4e6ea69 commit 3e72d47
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .kitchen.dokken.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ platforms:
- name: opensuse-leap
driver:
image: dokken/opensuse-leap
pid_one_command: /bin/systemd
pid_one_command: /bin/systemd
4 changes: 4 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ suites:
run_list:
- recipe[chef-grafana::default]
attributes:
chef-grafana:
config:
security:
admin_password: "non-default"
1 change: 1 addition & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
end

depends 'apt'
depends 'dpkg_autostart'
depends 'yum'

source_url 'https://github.com/chef-cookbooks/chef-grafana'
Expand Down
6 changes: 5 additions & 1 deletion recipes/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
components ['main']
action :add
end

dpkg_autostart 'grafana-server' do
allow false
end
when 'rhel'
yum_repository 'grafana' do
description "Grafana - #{node['chef-grafana']['install']['channel']}"
Expand All @@ -32,5 +36,5 @@
end

service 'grafana-server' do
action [:enable, :start]
action :enable
end
5 changes: 5 additions & 0 deletions test/integration/default/serverspec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@
it { should be_mode 644 }
it { should contain '# Managed by Chef' }
end

# check if non-default admin password is set
describe command('curl -I http://localhost:3000/api/datasources -H "Authorization: Basic YWRtaW46bm9uLWRlZmF1bHQ="') do
its(:stdout) { should match '200 OK' }
end
end

0 comments on commit 3e72d47

Please sign in to comment.