Skip to content

Commit

Permalink
Add the ability to override package_source
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Beresford committed Nov 28, 2018
1 parent aa42444 commit 0c1ecc2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
20 changes: 17 additions & 3 deletions manifests/forwarder.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
# [*server*]
# The address of a server to send logs to.
#
# [*manage_package_source*]
# By default, this class will handle downloading the Splunk module you need
# but you can set this to false if you do not want that behaviour
#
# [*package_source*]
# The source URL for the splunk installation media (typically an RPM, MSI,
# etc). If a $src_root parameter is set in splunk::params, this will be
Expand Down Expand Up @@ -52,7 +56,8 @@
#
class splunk::forwarder (
$server = $splunk::params::server,
$package_source = $splunk::params::forwarder_pkg_src,
$manage_package_source = true,
$package_source = undef,
$package_name = $splunk::params::forwarder_pkg_name,
$package_ensure = $splunk::params::forwarder_pkg_ensure,
$logging_port = $splunk::params::logging_port,
Expand All @@ -78,6 +83,12 @@
$staging_subdir = $splunk::params::staging_subdir

$path_delimiter = $splunk::params::path_delimiter

$_package_source = $manage_package_source ? {
true => $splunk::params::forwarder_pkg_src,
false => $package_source
}

#no need for staging the source if we have yum or apt
if $pkg_provider != undef and $pkg_provider != 'yum' and $pkg_provider != 'apt' and $pkg_provider != 'chocolatey' {
include ::archive::staging
Expand All @@ -87,7 +98,7 @@
$staged_package = join($pkg_path_parts, $path_delimiter)

archive { $staged_package:
source => $package_source,
source => $_package_source,
extract => false,
before => Package[$package_name],
}
Expand All @@ -98,7 +109,10 @@
Package {
source => $pkg_provider ? {
'chocolatey' => undef,
default => pick($staged_package, $package_source),
default => $manage_package_source ? {
true => pick($staged_package, $_package_source),
false => $_package_source
}
},
}

Expand Down
21 changes: 17 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#
# Parameters:
#
# [*manage_package_source*]
# By default, this class will handle downloading the Splunk module you need
# but you can set this to false if you do not want that behaviour
#
# [*package_source*]
# The source URL for the splunk installation media (typically an RPM, MSI,
# etc). If a $src_root parameter is set in splunk::params, this will be
Expand Down Expand Up @@ -44,7 +48,8 @@
# Requires: nothing
#
class splunk (
$package_source = $splunk::params::server_pkg_src,
$manage_package_source = true,
$package_source = undef,
$package_name = $splunk::params::server_pkg_name,
$package_ensure = $splunk::params::server_pkg_ensure,
$server_service = $splunk::params::server_service,
Expand Down Expand Up @@ -76,6 +81,11 @@

$path_delimiter = $splunk::params::path_delimiter

$_package_source = $manage_package_source ? {
true => $splunk::params::server_pkg_src,
false => $package_source
}

if $pkg_provider != undef and $pkg_provider != 'yum' and $pkg_provider != 'apt' and $pkg_provider != 'chocolatey' {
include ::archive::staging
$src_pkg_filename = basename($package_source)
Expand All @@ -91,10 +101,13 @@
$staged_package = undef
}

Package {
source => $pkg_provider ? {
Package {
source => $pkg_provider ? {
'chocolatey' => undef,
default => pick($staged_package, $package_source),
default => $manage_package_source ? {
true => pick($staged_package, $_package_source),
false => $_package_source
}
},
}

Expand Down
13 changes: 13 additions & 0 deletions spec/classes/forwarder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@

it { is_expected.to compile.with_all_deps }
end

context 'with pkg_provider set to yum and manage_package_source set to false' do
let(:params) { {
'pkg_provider' => 'yum',
'package_name' => 'splunk_forwarder_X',
'manage_package_source' => false
} }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('splunk_forwarder_X').with_provider('yum').without_source }
end
end
end


end
11 changes: 11 additions & 0 deletions spec/classes/splunk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
it { is_expected.to contain_service('splunk') }
it { is_expected.to contain_package('splunk').with_ensure('installed') }
end

context 'with pkg_provider set to yum and manage_package_source set to false' do
let(:params) { {
'pkg_provider' => 'yum',
'package_name' => 'splunk_server_X',
'manage_package_source' => false,
} }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('splunk_server_X').with_provider('yum').without_source }
end
end
end
end
Expand Down

0 comments on commit 0c1ecc2

Please sign in to comment.