Skip to content

Commit

Permalink
Merge pull request #209 from beezly/feature/fix_unmanged_repos
Browse files Browse the repository at this point in the history
Add the ability to override package_source
  • Loading branch information
alexjfisher authored Dec 5, 2018
2 parents aa42444 + 4364238 commit 4fe1532
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 63 deletions.
62 changes: 38 additions & 24 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 @@ -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],
}
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
73 changes: 43 additions & 30 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,57 +48,66 @@
# 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
$staging_subdir = $splunk::params::staging_subdir

$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],
}
} else {
$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
18 changes: 9 additions & 9 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
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) 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
13 changes: 13 additions & 0 deletions spec/classes/splunk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4fe1532

Please sign in to comment.