Skip to content

Commit 6bf969e

Browse files
committed
Fix module errors discovered while testing.
- The $splunk_user variable was referenced but undeclared. for this repo. - Update the build and version to correctly reference the most recent values. - The $staged_package variable was referenced before declaration. - Creates separate spec files for testing the splunk and splunk::forwarder classes. - Removes the path parameter from the enable_splunk and enable_splunkforwarder execs because it causes issues on platforms that use the systemd service provider. The resulting init script that the exec generates will not get loaded by the systemd-sysv-generate module. - Fixes an issue where the splunkweb Service would change from 'stopped' to 'running' on every Puppet run. The pattern for discovering the running service had an incorrect regex.
1 parent 7566958 commit 6bf969e

File tree

7 files changed

+76
-70
lines changed

7 files changed

+76
-70
lines changed

manifests/forwarder.pp

-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@
128128
# dependency chains.
129129
include splunk::virtual
130130

131-
realize Package[$package_name]
132131
realize Service[$virtual_service]
133132

134133
Package <| title == $package_name |> ->

manifests/init.pp

+11-10
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@
4343
# Requires: nothing
4444
#
4545
class splunk (
46-
$package_source = $splunk::params::server_pkg_src,
47-
$package_name = $splunk::params::server_pkg_name,
48-
$package_ensure = $splunk::params::server_pkg_ensure,
49-
$logging_port = $splunk::params::logging_port,
50-
$splunkd_port = $splunk::params::splunkd_port,
51-
$pkg_provider = $splunk::params::pkg_provider,
52-
$splunkd_listen = '127.0.0.1',
53-
$web_port = '8000',
46+
$package_source = $splunk::params::server_pkg_src,
47+
$package_name = $splunk::params::server_pkg_name,
48+
$package_ensure = $splunk::params::server_pkg_ensure,
49+
$logging_port = $splunk::params::logging_port,
50+
$splunkd_port = $splunk::params::splunkd_port,
51+
$splunk_user = $splunk::params::splunk_user,
52+
$pkg_provider = $splunk::params::pkg_provider,
53+
$splunkd_listen = '127.0.0.1',
54+
$web_port = '8000',
5455
$purge_authentication = false,
5556
$purge_authorize = false,
5657
$purge_distsearch = false,
@@ -71,11 +72,12 @@
7172

7273
if $pkg_provider != undef and $pkg_provider != 'yum' and $pkg_provider != 'apt' {
7374
include staging
75+
76+
$staged_package = staging_parse($package_source)
7477
$pkg_path_parts = [$staging::path, $staging_subdir, $staged_package]
7578
$pkg_source = join($pkg_path_parts, $path_delimiter)
7679

7780
#no need for staging the source if we have yum or apt
78-
$staged_package = staging_parse($package_source)
7981
staging::file { $staged_package:
8082
source => $package_source,
8183
subdir => $staging_subdir,
@@ -182,7 +184,6 @@
182184

183185
# This realize() call is because the collectors don't seem to work well with
184186
# arrays. They'll set the dependencies but not realize all Service resources
185-
realize(Package[$package_name])
186187
realize(Service[$virtual_service])
187188

188189
Package <| title == $package_name |> ->

manifests/params.pp

+4-3
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
# Requires: nothing
6868
#
6969
class splunk::params (
70-
$version = '5.0.5',
71-
$build = '179365',
70+
$version = '6.3.3',
71+
$build = 'f44afce176d0',
7272
$src_root = 'puppet:///modules/splunk',
7373
$splunkd_port = '8089',
7474
$logging_port = '9997',
@@ -127,7 +127,7 @@
127127
$forwarder_service = [ 'SplunkForwarder' ] # UNKNOWN
128128
$forwarder_confdir = "${forwarder_dir}/etc/system/local"
129129
$server_src_subdir = 'splunk/windows'
130-
$server_service = [ 'Splunkd', 'Splunkweb' ] # UNKNOWN
130+
$server_service = [ 'Splunkd', 'SplunkWeb' ] # UNKNOWN
131131
$server_confdir = "${server_dir}/etc/system/local"
132132
$forwarder_install_options = [
133133
'AGREETOLICENSE=Yes',
@@ -238,6 +238,7 @@
238238
$create_password = true
239239

240240
$forwarder_pkg_ensure = 'installed'
241+
$splunk_user = 'root'
241242

242243
# A meta resource so providers know where splunk is installed:
243244
splunk_config { 'splunk':

manifests/platform/posix.pp

+10-7
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,43 @@
1616
#
1717
class splunk::platform::posix (
1818
$splunkd_port = $splunk::splunkd_port,
19+
$splunk_user = $splunk::params::splunk_user,
1920
) inherits splunk::virtual {
2021

22+
include ::splunk::params
2123
# Many of the resources declared here are virtual. They will be realized by
2224
# the appropriate including class if required.
2325

2426
# Commands to run to enable the SplunkUniversalForwarder
2527
@exec { 'license_splunkforwarder':
26-
path => '/opt/splunkforwarder/bin',
28+
path => "${splunk::params::forwarder_dir}/bin",
2729
command => 'splunk start --accept-license --answer-yes',
2830
user => $splunk_user,
2931
creates => '/opt/splunkforwarder/etc/auth/server.pem',
3032
timeout => 0,
3133
tag => 'splunk_forwarder',
3234
}
3335
@exec { 'enable_splunkforwarder':
34-
path => '/opt/splunkforwarder/bin',
35-
command => "splunk enable boot-start -user $splunk_user",
36+
37+
# The path parameter can't be set because the boot-start silently fails on systemd service providers
38+
command => "${splunk::params::forwarder_dir}/bin/splunk enable boot-start -user ${splunk_user}",
3639
creates => '/etc/init.d/splunk',
3740
require => Exec['license_splunkforwarder'],
3841
tag => 'splunk_forwarder',
3942
}
4043

4144
# Commands to run to enable full Splunk
4245
@exec { 'license_splunk':
43-
path => '/opt/splunk/bin',
46+
path => "${splunk::params::server_dir}/bin",
4447
command => 'splunk start --accept-license --answer-yes',
4548
user => $splunk_user,
4649
creates => '/opt/splunk/etc/auth/splunk.secret',
4750
timeout => 0,
4851
tag => 'splunk_server',
4952
}
5053
@exec { 'enable_splunk':
51-
path => '/opt/splunk/bin',
52-
command => "splunk enable boot-start -user $splunk_user",
54+
# The path parameter can't be set because the boot-start silently fails on systemd service providers
55+
command => "${splunk::params::server_dir}/bin/splunk enable boot-start -user ${splunk_user}",
5356
creates => '/etc/init.d/splunk',
5457
require => Exec['license_splunk'],
5558
tag => 'splunk_server',
@@ -71,7 +74,7 @@
7174
restart => '/opt/splunk/bin/splunk restart splunkweb',
7275
start => '/opt/splunk/bin/splunk start splunkweb',
7376
stop => '/opt/splunk/bin/splunk stop splunkweb',
74-
pattern => 'python -O /opt/splunk/lib/python.*/splunk/.*/root.py (restart|start)',
77+
pattern => 'python -O /opt/splunk/lib/python.*/splunk/.*/root.py.*',
7578
require => Service['splunk'],
7679
}
7780

spec/acceptance/class_spec.rb

-49
This file was deleted.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'splunk::forwarder class' do
4+
context 'default parameters' do
5+
# Using puppet_apply as a helper
6+
it 'should work idempotently with no errors' do
7+
pp = <<-EOS
8+
class { '::splunk::forwarder': }
9+
EOS
10+
11+
# Run it twice and test for idempotency
12+
apply_manifest(pp, :catch_failures => true)
13+
apply_manifest(pp, :catch_changes => true)
14+
end
15+
16+
describe package('splunkforwarder') do
17+
it { is_expected.to be_installed }
18+
end
19+
20+
describe service('splunk') do
21+
it { is_expected.to be_enabled }
22+
it { is_expected.to be_running }
23+
end
24+
end
25+
end

spec/acceptance/splunk_spec.rb

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'splunk class' do
4+
context 'default parameters' do
5+
# Using puppet_apply as a helper
6+
it 'should work idempotently with no errors' do
7+
pp = <<-EOS
8+
class { '::splunk': }
9+
EOS
10+
11+
# Run it twice and test for idempotency
12+
apply_manifest(pp, :catch_failures => true)
13+
apply_manifest(pp, :catch_changes => true)
14+
end
15+
16+
describe package('splunk') do
17+
it { is_expected.to be_installed }
18+
end
19+
20+
describe service('splunk') do
21+
it { is_expected.to be_enabled }
22+
it { is_expected.to be_running }
23+
end
24+
end
25+
end
26+

0 commit comments

Comments
 (0)