Skip to content

Commit

Permalink
Rely on Hiera to get the package name
Browse files Browse the repository at this point in the history
Using Hiera hierarchy, we can provide a default value that makes sense
for the current operating system and still allow the user to provide
their own custom package name if necessary.

Makes the code simpler without changing the logic.
  • Loading branch information
smortex committed Sep 3, 2024
1 parent f426182 commit a65a89a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 19 deletions.
1 change: 1 addition & 0 deletions data/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ patterndb::base_dir: /
patterndb::temp_dir: /tmp/syslog-ng
patterndb::package_name: false
patterndb::manage_package: true
patterndb::package_name: syslog-ng
patterndb::syslogng_modules: []
patterndb::use_hiera: false
patterndb::_manage_top_dirs: true
Expand Down
2 changes: 2 additions & 0 deletions data/osfamily/Debian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
patterndb::package_name: syslog-ng-core
14 changes: 2 additions & 12 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
class patterndb (
String[1] $package_name,
String[1] $base_dir = '/',
String[1] $temp_dir = "${base_dir}/tmp/syslog-ng",
Variant[String[1],Boolean] $package_name = false,
Boolean $manage_package = true,
Array[String[1]] $syslogng_modules = [],
Boolean $use_hiera = false,
Expand All @@ -11,17 +11,7 @@
) {
# package
if $manage_package {
if $package_name =~ String {
$real_package_name = $package_name
} else {
case $facts['os']['family'] {
'RedHat': { $real_package_name = 'syslog-ng' }
'Debian': { $real_package_name = 'syslog-ng-core' }
'FreeBSD': { $real_package_name = 'syslog-ng' }
default: { fail("unsupported osfamily: ${facts['os']['family']}") }
}
}
ensure_resource ( 'package', $real_package_name, { 'ensure' => 'installed' })
ensure_resource ( 'package', $package_name, { 'ensure' => 'installed' })
}
ensure_resource ( 'file', $temp_dir, { ensure => directory })
if $_manage_top_dirs {
Expand Down
7 changes: 0 additions & 7 deletions spec/classes/patterndb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@
end
end
end
context 'Unsupported OS without package_name' do
let :facts do
{ osfamily: 'UnsupportedOne' }
end

it { is_expected.to raise_error(Puppet::Error) }
end

context 'Any OS with a package name' do
let :params do
Expand Down

0 comments on commit a65a89a

Please sign in to comment.