diff --git a/manifests/forwarder.pp b/manifests/forwarder.pp index 11bda731..50bc5f67 100644 --- a/manifests/forwarder.pp +++ b/manifests/forwarder.pp @@ -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 @@ -51,43 +55,50 @@ # Requires: nothing # class splunk::forwarder ( - $server = $splunk::params::server, - $package_source = $splunk::params::forwarder_pkg_src, - $package_name = $splunk::params::forwarder_pkg_name, - $package_ensure = $splunk::params::forwarder_pkg_ensure, - $logging_port = $splunk::params::logging_port, - $splunkd_port = $splunk::params::splunkd_port, - $install_options = $splunk::params::forwarder_install_options, - $splunk_user = $splunk::params::splunk_user, - $splunkd_listen = '127.0.0.1', - $purge_deploymentclient = false, - $purge_inputs = false, - $purge_outputs = false, - $purge_props = false, - $purge_transforms = false, - $purge_web = false, - $pkg_provider = $splunk::params::pkg_provider, - $forwarder_confdir = $splunk::params::forwarder_confdir, - $forwarder_output = $splunk::params::forwarder_output, - $forwarder_input = $splunk::params::forwarder_input, - $create_password = $splunk::params::create_password, - $addons = {}, + String $server = $splunk::params::server, + Boolean $manage_package_source = true, + Optional[String] $package_source = undef, + String $package_name = $splunk::params::forwarder_pkg_name, + String $package_ensure = $splunk::params::forwarder_pkg_ensure, + Stdlib::Port $logging_port = $splunk::params::logging_port, + Stdlib::Port $splunkd_port = $splunk::params::splunkd_port, + Optional[Array] $install_options = $splunk::params::forwarder_install_options, + String $splunk_user = $splunk::params::splunk_user, + Stdlib::Host $splunkd_listen = '127.0.0.1', + Boolean $purge_deploymentclient = false, + Boolean $purge_inputs = false, + Boolean $purge_outputs = false, + Boolean $purge_props = false, + Boolean $purge_transforms = false, + Boolean $purge_web = false, + Optional[String] $pkg_provider = $splunk::params::pkg_provider, + String $forwarder_confdir = $splunk::params::forwarder_confdir, + Hash $forwarder_output = $splunk::params::forwarder_output, + Hash $forwarder_input = $splunk::params::forwarder_input, + Boolean $create_password = $splunk::params::create_password, + Hash $addons = {}, ) inherits splunk::params { $virtual_service = $splunk::params::forwarder_service $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 - $src_pkg_filename = basename($package_source) + $src_pkg_filename = basename($_package_source) $pkg_path_parts = [$archive::path, $staging_subdir, $src_pkg_filename] $staged_package = join($pkg_path_parts, $path_delimiter) archive { $staged_package: - source => $package_source, + source => $_package_source, extract => false, before => Package[$package_name], } @@ -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, + } }, } diff --git a/manifests/init.pp b/manifests/init.pp index 7d54cdac..30a604c1 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 @@ -44,31 +48,32 @@ # Requires: nothing # class splunk ( - $package_source = $splunk::params::server_pkg_src, - $package_name = $splunk::params::server_pkg_name, - $package_ensure = $splunk::params::server_pkg_ensure, - $server_service = $splunk::params::server_service, - $logging_port = $splunk::params::logging_port, - $splunkd_port = $splunk::params::splunkd_port, - $splunk_user = $splunk::params::splunk_user, - $pkg_provider = $splunk::params::pkg_provider, - $splunkd_listen = '127.0.0.1', - $web_port = '8000', - $purge_alert_actions = false, - $purge_authentication = false, - $purge_authorize = false, - $purge_deploymentclient = false, - $purge_distsearch = false, - $purge_indexes = false, - $purge_inputs = false, - $purge_limits = false, - $purge_outputs = false, - $purge_props = false, - $purge_server = false, - $purge_serverclass = false, - $purge_transforms = false, - $purge_uiprefs = false, - $purge_web = false, + Boolean $manage_package_source = true, + Optional[String] $package_source = undef, + String $package_name = $splunk::params::server_pkg_name, + String $package_ensure = $splunk::params::server_pkg_ensure, + Variant[Array[String],String] $server_service = $splunk::params::server_service, + Stdlib::Port $logging_port = $splunk::params::logging_port, + Stdlib::Port $splunkd_port = $splunk::params::splunkd_port, + String $splunk_user = $splunk::params::splunk_user, + Optional[String] $pkg_provider = $splunk::params::pkg_provider, + Stdlib::Host $splunkd_listen = '127.0.0.1', + Stdlib::Port $web_port = 8000, + Boolean $purge_alert_actions = false, + Boolean $purge_authentication = false, + Boolean $purge_authorize = false, + Boolean $purge_deploymentclient = false, + Boolean $purge_distsearch = false, + Boolean $purge_indexes = false, + Boolean $purge_inputs = false, + Boolean $purge_limits = false, + Boolean $purge_outputs = false, + Boolean $purge_props = false, + Boolean $purge_server = false, + Boolean $purge_serverclass = false, + Boolean $purge_transforms = false, + Boolean $purge_uiprefs = false, + Boolean $purge_web = false, ) inherits splunk::params { $virtual_service = $server_service @@ -76,14 +81,19 @@ $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) + $src_pkg_filename = basename($_package_source) $pkg_path_parts = [$archive::path, $staging_subdir, $src_pkg_filename] $staged_package = join($pkg_path_parts, $path_delimiter) archive { $staged_package: - source => $package_source, + source => $_package_source, extract => false, before => Package[$package_name], } @@ -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, + } }, } diff --git a/manifests/params.pp b/manifests/params.pp index bb31d2aa..ea9f966d 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -81,15 +81,15 @@ # Requires: nothing # class splunk::params ( - $version = '7.0.0', - $build = 'c8a78efdd40f', - $src_root = 'https://download.splunk.com', - $splunkd_port = '8089', - $logging_port = '9997', - $server = 'splunk', - $forwarder_installdir = undef, - $server_installdir = undef, - $splunk_user = $facts['os']['family'] ? { + String $version = '7.0.0', + String $build = 'c8a78efdd40f', + String $src_root = 'https://download.splunk.com', + Stdlib::Port $splunkd_port = 8089, + Stdlib::Port $logging_port = 9997, + String $server = 'splunk', + Optional[String] $forwarder_installdir = undef, + Optional[String] $server_installdir = undef, + String $splunk_user = $facts['os']['family'] ? { 'Windows' => 'Administrator', default => 'root' } diff --git a/spec/classes/forwarder_spec.rb b/spec/classes/forwarder_spec.rb index 2291f1a3..cd116172 100644 --- a/spec/classes/forwarder_spec.rb +++ b/spec/classes/forwarder_spec.rb @@ -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) do + { + 'pkg_provider' => 'yum', + 'package_name' => 'splunk_forwarder_X', + 'manage_package_source' => false + } + end + + 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 diff --git a/spec/classes/splunk_spec.rb b/spec/classes/splunk_spec.rb index 9c46a528..d656b0f2 100644 --- a/spec/classes/splunk_spec.rb +++ b/spec/classes/splunk_spec.rb @@ -19,6 +19,19 @@ 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) do + { + 'pkg_provider' => 'yum', + 'package_name' => 'splunk_server_X', + 'manage_package_source' => false + } + end + + 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