Skip to content

Commit 60916bd

Browse files
authored
Merge pull request bfraser#115 from ZeroPointEnergy/feature/sysconfig
Manage sysconfig files
2 parents a90354c + b40f064 commit 60916bd

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,25 @@ Defaults to 'grafana-server'.
304304
The version of Grafana to install and manage. Defaults to the latest version of
305305
Grafana available at the time of module release.
306306

307+
##### `sysconfig_location`
308+
309+
The RPM and DEB packages bring with them the default environment files for the
310+
services. The default location of this file for Debian is /etc/default/grafana-server
311+
and for RedHat /etc/sysconfig/grafana-server.
312+
313+
##### `sysconfig`
314+
315+
A hash of environment variables for the service. This only has an effect for installations
316+
with RPM and DEB packages (if install_method is set to 'package' or 'repo').
317+
318+
Example:
319+
320+
```puppet
321+
sysconfig => {
322+
'http_proxy' => 'http://proxy.example.com',
323+
}
324+
```
325+
307326
### Advanced usage
308327

309328
The archive install method will create the user and a "command line" service by

manifests/config.pp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
owner => 'grafana',
2626
group => 'grafana',
2727
}
28+
29+
$sysconfig = $::grafana::sysconfig
30+
$sysconfig_location = $::grafana::sysconfig_location
31+
32+
if $sysconfig_location and $sysconfig {
33+
$changes = $sysconfig.map |$key, $value| { "set ${key} ${value}" }
34+
35+
augeas{'sysconfig/grafana-server':
36+
context => "/files${$sysconfig_location}",
37+
changes => $changes,
38+
}
39+
}
2840
}
2941
'archive': {
3042
$cfg = $::grafana::cfg

manifests/init.pp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@
6666
# A hash of plugins to be passed to `create_resources`, wraps around the
6767
# `grafana_plugin` resource.
6868
#
69+
# [*sysconfig_location*]
70+
# Location of the sysconfig file for the environment of the grafana-server service.
71+
# This is only used when the install_method is 'package' or 'repo'.
72+
#
73+
# [*sysconfig*]
74+
# A hash of environment variables for the grafana-server service
75+
#
76+
# Example:
77+
# sysconfig => { 'http_proxy' => 'http://proxy.example.com/' }
78+
#
6979
# === Examples
7080
#
7181
# class { '::grafana':
@@ -89,7 +99,9 @@
8999
String $rpm_iteration = $::grafana::params::rpm_iteration,
90100
String $service_name = $::grafana::params::service_name,
91101
String $version = $::grafana::params::version,
92-
Hash $plugins = {}
102+
Hash $plugins = {},
103+
Optional[String] $sysconfig_location = $::grafana::params::sysconfig_location,
104+
Optional[Hash] $sysconfig = undef,
93105
) inherits grafana::params {
94106

95107
contain grafana::install

manifests/params.pp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,28 @@
2121
$install_method = 'repo'
2222
$cfg_location = '/etc/grafana.ini'
2323
$service_name = 'grafana'
24+
$sysconfig_location = undef
2425
}
25-
'Debian', 'RedHat': {
26+
'Debian': {
2627
$manage_package_repo = true
2728
$install_method = 'repo'
2829
$cfg_location = '/etc/grafana/grafana.ini'
2930
$service_name = 'grafana-server'
31+
$sysconfig_location = '/etc/default/grafana-server'
32+
}
33+
'RedHat': {
34+
$manage_package_repo = true
35+
$install_method = 'repo'
36+
$cfg_location = '/etc/grafana/grafana.ini'
37+
$service_name = 'grafana-server'
38+
$sysconfig_location = '/etc/sysconfig/grafana-server'
3039
}
3140
default: {
3241
$manage_package_repo = true
3342
$install_method = 'package'
3443
$cfg_location = '/etc/grafana/grafana.ini'
3544
$service_name = 'grafana-server'
45+
$sysconfig_location = undef
3646
}
3747
}
3848
}

spec/classes/grafana_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,28 @@
309309
it { is_expected.to contain_file('/etc/grafana/ldap.toml').with_content(ldap_expected) }
310310
end
311311
end
312+
313+
context 'sysconfig environment variables' do
314+
let(:params) do
315+
{
316+
install_method: 'repo',
317+
sysconfig: { http_proxy: 'http://proxy.example.com/' }
318+
}
319+
end
320+
321+
case facts[:osfamily]
322+
when 'Debian'
323+
describe 'Add the environment variable to the config file' do
324+
it { is_expected.to contain_augeas('sysconfig/grafana-server').with_context('/files/etc/default/grafana-server') }
325+
it { is_expected.to contain_augeas('sysconfig/grafana-server').with_changes(['set http_proxy http://proxy.example.com/']) }
326+
end
327+
when 'RedHat'
328+
describe 'Add the environment variable to the config file' do
329+
it { is_expected.to contain_augeas('sysconfig/grafana-server').with_context('/files/etc/sysconfig/grafana-server') }
330+
it { is_expected.to contain_augeas('sysconfig/grafana-server').with_changes(['set http_proxy http://proxy.example.com/']) }
331+
end
332+
end
333+
end
312334
end
313335
end
314336
end

0 commit comments

Comments
 (0)