Skip to content

Commit

Permalink
Merge pull request bfraser#115 from ZeroPointEnergy/feature/sysconfig
Browse files Browse the repository at this point in the history
Manage sysconfig files
  • Loading branch information
bastelfreak authored Jun 21, 2018
2 parents a90354c + b40f064 commit 60916bd
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,25 @@ Defaults to 'grafana-server'.
The version of Grafana to install and manage. Defaults to the latest version of
Grafana available at the time of module release.

##### `sysconfig_location`

The RPM and DEB packages bring with them the default environment files for the
services. The default location of this file for Debian is /etc/default/grafana-server
and for RedHat /etc/sysconfig/grafana-server.

##### `sysconfig`

A hash of environment variables for the service. This only has an effect for installations
with RPM and DEB packages (if install_method is set to 'package' or 'repo').

Example:

```puppet
sysconfig => {
'http_proxy' => 'http://proxy.example.com',
}
```

### Advanced usage

The archive install method will create the user and a "command line" service by
Expand Down
12 changes: 12 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
owner => 'grafana',
group => 'grafana',
}

$sysconfig = $::grafana::sysconfig
$sysconfig_location = $::grafana::sysconfig_location

if $sysconfig_location and $sysconfig {
$changes = $sysconfig.map |$key, $value| { "set ${key} ${value}" }

augeas{'sysconfig/grafana-server':
context => "/files${$sysconfig_location}",
changes => $changes,
}
}
}
'archive': {
$cfg = $::grafana::cfg
Expand Down
14 changes: 13 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@
# A hash of plugins to be passed to `create_resources`, wraps around the
# `grafana_plugin` resource.
#
# [*sysconfig_location*]
# Location of the sysconfig file for the environment of the grafana-server service.
# This is only used when the install_method is 'package' or 'repo'.
#
# [*sysconfig*]
# A hash of environment variables for the grafana-server service
#
# Example:
# sysconfig => { 'http_proxy' => 'http://proxy.example.com/' }
#
# === Examples
#
# class { '::grafana':
Expand All @@ -89,7 +99,9 @@
String $rpm_iteration = $::grafana::params::rpm_iteration,
String $service_name = $::grafana::params::service_name,
String $version = $::grafana::params::version,
Hash $plugins = {}
Hash $plugins = {},
Optional[String] $sysconfig_location = $::grafana::params::sysconfig_location,
Optional[Hash] $sysconfig = undef,
) inherits grafana::params {

contain grafana::install
Expand Down
12 changes: 11 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,28 @@
$install_method = 'repo'
$cfg_location = '/etc/grafana.ini'
$service_name = 'grafana'
$sysconfig_location = undef
}
'Debian', 'RedHat': {
'Debian': {
$manage_package_repo = true
$install_method = 'repo'
$cfg_location = '/etc/grafana/grafana.ini'
$service_name = 'grafana-server'
$sysconfig_location = '/etc/default/grafana-server'
}
'RedHat': {
$manage_package_repo = true
$install_method = 'repo'
$cfg_location = '/etc/grafana/grafana.ini'
$service_name = 'grafana-server'
$sysconfig_location = '/etc/sysconfig/grafana-server'
}
default: {
$manage_package_repo = true
$install_method = 'package'
$cfg_location = '/etc/grafana/grafana.ini'
$service_name = 'grafana-server'
$sysconfig_location = undef
}
}
}
22 changes: 22 additions & 0 deletions spec/classes/grafana_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,28 @@
it { is_expected.to contain_file('/etc/grafana/ldap.toml').with_content(ldap_expected) }
end
end

context 'sysconfig environment variables' do
let(:params) do
{
install_method: 'repo',
sysconfig: { http_proxy: 'http://proxy.example.com/' }
}
end

case facts[:osfamily]
when 'Debian'
describe 'Add the environment variable to the config file' do
it { is_expected.to contain_augeas('sysconfig/grafana-server').with_context('/files/etc/default/grafana-server') }
it { is_expected.to contain_augeas('sysconfig/grafana-server').with_changes(['set http_proxy http://proxy.example.com/']) }
end
when 'RedHat'
describe 'Add the environment variable to the config file' do
it { is_expected.to contain_augeas('sysconfig/grafana-server').with_context('/files/etc/sysconfig/grafana-server') }
it { is_expected.to contain_augeas('sysconfig/grafana-server').with_changes(['set http_proxy http://proxy.example.com/']) }
end
end
end
end
end
end

0 comments on commit 60916bd

Please sign in to comment.