extract.pp |
|
---|---|
Define: staging::extractDefine resource to extract files from staging directories to target directories. Parameters:
Usage:
|
define staging::extract (
$target,
$source = undef,
$creates = undef,
$unless = undef,
$onlyif = undef,
$user = undef,
$group = undef,
$environment = undef,
$subdir = $caller_module_name
) {
include staging
if $source {
$source_path = $source
} else {
$source_path = "${staging::path}/${subdir}/${name}"
} |
Use user supplied creates path, set default value if creates, unless or onlyif is not supplied. |
if $creates {
$creates_path = $creates
} elsif ! ($unless or $onlyif) {
if $name =~ /.tar.gz$/ {
$folder = staging_parse($name, 'basename', '.tar.gz')
$creates_path = "${target}/${folder}"
} else {
$folder = staging_parse($name, 'basename')
$creates_path = "${target}/${folder}"
}
}
if scope_defaults('Exec','path') {
Exec{
cwd => $target,
user => $user,
group => $group,
environment => $environment,
creates => $creates_path,
unless => $unless,
onlyif => $onlyif,
logoutput => on_failure,
}
} else {
Exec{
path => $::path,
cwd => $target,
user => $user,
group => $group,
environment => $environment,
creates => $creates_path,
unless => $unless,
onlyif => $onlyif,
logoutput => on_failure,
}
}
case $name {
/.tar$/: {
$command = "tar xf ${source_path}"
}
/(.tgz|.tar.gz)$/: {
if $::osfamily == 'Solaris' {
$command = "gunzip -dc < ${source_path} | tar xf - "
} else {
$command = "tar xzf ${source_path}"
}
}
/.zip$/: {
$command = "unzip ${source_path}"
}
/.war$/: {
$command = "jar xf ${source_path}"
}
default: {
fail("staging::extract: unsupported file format ${name}.")
}
}
exec { "extract ${name}":
command => $command,
}
} |