Skip to content

Commit 0ae1bcd

Browse files
authored
Merge pull request #269 from treydock/accept-tos
Support upgrading splunk forwarding and accepting ToS
2 parents f818422 + b30a607 commit 0ae1bcd

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

manifests/forwarder/service/nix.pp

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
class splunk::forwarder::service::nix inherits splunk::forwarder::service {
66

77
if $splunk::forwarder::boot_start {
8+
$accept_tos_user = 'root'
9+
$accept_tos_require = Exec['enable_splunkforwarder']
810
# Ensure splunk services *not* managed by the system service file are
911
# gracefully shut down prior to enabling boot-start. Should the service
1012
# file be enabled while binary-managed splunk services are running, you
@@ -36,6 +38,8 @@
3638
# Commands to license and disable the SplunkUniversalForwarder
3739
#
3840
else {
41+
$accept_tos_user = $splunk::forwarder::splunk_user
42+
$accept_tos_require = Exec['license_splunkforwarder']
3943
# Accept the license when disabling splunk in case system service files are
4044
# present before installing splunk. The splunk package does not remove the
4145
# service files when uninstalled.
@@ -72,4 +76,24 @@
7276
}
7377
}
7478

79+
# If forwarder is already installed, refresh from package changes
80+
if $facts['splunkforwarder_version'] {
81+
$accept_tos_subscribe = Package[$splunk::forwarder::package_name]
82+
} else {
83+
$accept_tos_subscribe = undef
84+
}
85+
$accept_tos_command = [
86+
"${splunk::forwarder::forwarder_homedir}/bin/splunk stop &&",
87+
"${splunk::forwarder::forwarder_homedir}/bin/splunk start --accept-license --answer-yes &&",
88+
"${splunk::forwarder::forwarder_homedir}/bin/splunk stop",
89+
]
90+
exec { 'splunk-forwarder-accept-tos':
91+
command => join($accept_tos_command, ' '),
92+
user => $accept_tos_user,
93+
before => Service[$splunk::forwarder::service_name],
94+
subscribe => $accept_tos_subscribe,
95+
require => $accept_tos_require,
96+
refreshonly => true,
97+
}
98+
7599
}

spec/classes/forwarder_spec.rb

+48
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,54 @@
228228

229229
end
230230
end
231+
232+
context 'when forwarder not already installed' do
233+
let(:facts) do
234+
facts.merge(splunkforwarder_version: nil, service_provider: 'systemd')
235+
end
236+
let(:pre_condition) do
237+
"class { 'splunk::params': version => '7.2.2' }"
238+
end
239+
let(:accept_tos_command) do
240+
'/opt/splunkforwarder/bin/splunk stop && /opt/splunkforwarder/bin/splunk start --accept-license --answer-yes && /opt/splunkforwarder/bin/splunk stop'
241+
end
242+
243+
it_behaves_like 'splunk forwarder'
244+
it do
245+
is_expected.to contain_exec('splunk-forwarder-accept-tos').with(
246+
command: accept_tos_command,
247+
user: 'root',
248+
before: 'Service[SplunkForwarder]',
249+
subscribe: nil,
250+
require: 'Exec[enable_splunkforwarder]',
251+
refreshonly: 'true'
252+
)
253+
end
254+
end
255+
256+
context 'when forwarder already installed' do
257+
let(:facts) do
258+
facts.merge(splunkforwarder_version: '7.3.3', service_provider: 'systemd')
259+
end
260+
let(:pre_condition) do
261+
"class { 'splunk::params': version => '7.2.2' }"
262+
end
263+
let(:accept_tos_command) do
264+
'/opt/splunkforwarder/bin/splunk stop && /opt/splunkforwarder/bin/splunk start --accept-license --answer-yes && /opt/splunkforwarder/bin/splunk stop'
265+
end
266+
267+
it_behaves_like 'splunk forwarder'
268+
it do
269+
is_expected.to contain_exec('splunk-forwarder-accept-tos').with(
270+
command: accept_tos_command,
271+
user: 'root',
272+
before: 'Service[SplunkForwarder]',
273+
subscribe: 'Package[splunkforwarder]',
274+
require: 'Exec[enable_splunkforwarder]',
275+
refreshonly: 'true'
276+
)
277+
end
278+
end
231279
end
232280
end
233281
end

0 commit comments

Comments
 (0)