Skip to content

Commit 0c1ecc2

Browse files
author
Andrew Beresford
committed
Add the ability to override package_source
1 parent aa42444 commit 0c1ecc2

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

manifests/forwarder.pp

+17-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
# [*server*]
99
# The address of a server to send logs to.
1010
#
11+
# [*manage_package_source*]
12+
# By default, this class will handle downloading the Splunk module you need
13+
# but you can set this to false if you do not want that behaviour
14+
#
1115
# [*package_source*]
1216
# The source URL for the splunk installation media (typically an RPM, MSI,
1317
# etc). If a $src_root parameter is set in splunk::params, this will be
@@ -52,7 +56,8 @@
5256
#
5357
class splunk::forwarder (
5458
$server = $splunk::params::server,
55-
$package_source = $splunk::params::forwarder_pkg_src,
59+
$manage_package_source = true,
60+
$package_source = undef,
5661
$package_name = $splunk::params::forwarder_pkg_name,
5762
$package_ensure = $splunk::params::forwarder_pkg_ensure,
5863
$logging_port = $splunk::params::logging_port,
@@ -78,6 +83,12 @@
7883
$staging_subdir = $splunk::params::staging_subdir
7984

8085
$path_delimiter = $splunk::params::path_delimiter
86+
87+
$_package_source = $manage_package_source ? {
88+
true => $splunk::params::forwarder_pkg_src,
89+
false => $package_source
90+
}
91+
8192
#no need for staging the source if we have yum or apt
8293
if $pkg_provider != undef and $pkg_provider != 'yum' and $pkg_provider != 'apt' and $pkg_provider != 'chocolatey' {
8394
include ::archive::staging
@@ -87,7 +98,7 @@
8798
$staged_package = join($pkg_path_parts, $path_delimiter)
8899

89100
archive { $staged_package:
90-
source => $package_source,
101+
source => $_package_source,
91102
extract => false,
92103
before => Package[$package_name],
93104
}
@@ -98,7 +109,10 @@
98109
Package {
99110
source => $pkg_provider ? {
100111
'chocolatey' => undef,
101-
default => pick($staged_package, $package_source),
112+
default => $manage_package_source ? {
113+
true => pick($staged_package, $_package_source),
114+
false => $_package_source
115+
}
102116
},
103117
}
104118

manifests/init.pp

+17-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#
55
# Parameters:
66
#
7+
# [*manage_package_source*]
8+
# By default, this class will handle downloading the Splunk module you need
9+
# but you can set this to false if you do not want that behaviour
10+
#
711
# [*package_source*]
812
# The source URL for the splunk installation media (typically an RPM, MSI,
913
# etc). If a $src_root parameter is set in splunk::params, this will be
@@ -44,7 +48,8 @@
4448
# Requires: nothing
4549
#
4650
class splunk (
47-
$package_source = $splunk::params::server_pkg_src,
51+
$manage_package_source = true,
52+
$package_source = undef,
4853
$package_name = $splunk::params::server_pkg_name,
4954
$package_ensure = $splunk::params::server_pkg_ensure,
5055
$server_service = $splunk::params::server_service,
@@ -76,6 +81,11 @@
7681

7782
$path_delimiter = $splunk::params::path_delimiter
7883

84+
$_package_source = $manage_package_source ? {
85+
true => $splunk::params::server_pkg_src,
86+
false => $package_source
87+
}
88+
7989
if $pkg_provider != undef and $pkg_provider != 'yum' and $pkg_provider != 'apt' and $pkg_provider != 'chocolatey' {
8090
include ::archive::staging
8191
$src_pkg_filename = basename($package_source)
@@ -91,10 +101,13 @@
91101
$staged_package = undef
92102
}
93103

94-
Package {
95-
source => $pkg_provider ? {
104+
Package {
105+
source => $pkg_provider ? {
96106
'chocolatey' => undef,
97-
default => pick($staged_package, $package_source),
107+
default => $manage_package_source ? {
108+
true => pick($staged_package, $_package_source),
109+
false => $_package_source
110+
}
98111
},
99112
}
100113

spec/classes/forwarder_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@
2020

2121
it { is_expected.to compile.with_all_deps }
2222
end
23+
24+
context 'with pkg_provider set to yum and manage_package_source set to false' do
25+
let(:params) { {
26+
'pkg_provider' => 'yum',
27+
'package_name' => 'splunk_forwarder_X',
28+
'manage_package_source' => false
29+
} }
30+
31+
it { is_expected.to compile.with_all_deps }
32+
it { is_expected.to contain_package('splunk_forwarder_X').with_provider('yum').without_source }
33+
end
2334
end
2435
end
36+
37+
2538
end

spec/classes/splunk_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
it { is_expected.to contain_service('splunk') }
2020
it { is_expected.to contain_package('splunk').with_ensure('installed') }
2121
end
22+
23+
context 'with pkg_provider set to yum and manage_package_source set to false' do
24+
let(:params) { {
25+
'pkg_provider' => 'yum',
26+
'package_name' => 'splunk_server_X',
27+
'manage_package_source' => false,
28+
} }
29+
30+
it { is_expected.to compile.with_all_deps }
31+
it { is_expected.to contain_package('splunk_server_X').with_provider('yum').without_source }
32+
end
2233
end
2334
end
2435
end

0 commit comments

Comments
 (0)