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

pass options through env_vars if no control over init files #530

Merged
merged 9 commits into from
Mar 1, 2021
26 changes: 24 additions & 2 deletions manifests/daemon.pp
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,37 @@
'none': {}
}

unless $env_vars.empty {
if $init_style == 'none' and $install_method == 'package' {
$env_vars_merged = $env_vars + {
'ARGS' => $options,
}
} else {
$env_vars_merged = $env_vars
}

if $install_method == 'package' and $package_ensure in ['absent', 'purged'] {
# purge the environment file if the package is removed
#
# this is to make sure we can garbage-collect the files created by
# this module, when purging it.
file { "${env_file_path}/${name}":
ensure => absent,
}
} elsif $install_method == 'package' or !$env_vars_merged.empty {
# manage the environment file if the package is installed *or*, in
# any other case, if there's something to add to it
#
# the logic here is that the package-managed .service files *need*
# those files to be present, even if empty, so it's critical that
# the file not get removed
file { "${env_file_path}/${name}":
mode => '0644',
owner => 'root',
group => '0', # Darwin uses wheel
content => epp(
'prometheus/daemon.env.epp',
{
'env_vars' => $env_vars,
'env_vars' => $env_vars_merged,
}
),
notify => $notify_service,
Expand Down
8 changes: 6 additions & 2 deletions spec/classes/node_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
end

if facts[:os]['family'] == 'RedHat'
it { is_expected.not_to contain_file('/etc/sysconfig/bird_exporter') }
it { is_expected.not_to contain_file('/etc/sysconfig/node_exporter') }
elsif facts[:os]['name'] == 'Archlinux'
it { is_expected.to contain_file('/etc/default/node_exporter') }
it { is_expected.not_to contain_file('/etc/sysconfig/node_exporter') }
else
it { is_expected.not_to contain_file('/etc/default/bird_exporter') }
it { is_expected.not_to contain_file('/etc/default/node_exporter') }
it { is_expected.not_to contain_file('/etc/sysconfig/node_exporter') }
end
end

Expand Down