diff --git a/README.md b/README.md index be198db32..e535e493c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/manifests/config.pp b/manifests/config.pp index 725b10d9b..d357eb2e1 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -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 diff --git a/manifests/init.pp b/manifests/init.pp index 9897d9819..01343bfea 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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': @@ -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 diff --git a/manifests/params.pp b/manifests/params.pp index 062054afc..31544a130 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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 } } } diff --git a/spec/classes/grafana_spec.rb b/spec/classes/grafana_spec.rb index 780817210..9237efa67 100644 --- a/spec/classes/grafana_spec.rb +++ b/spec/classes/grafana_spec.rb @@ -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