/usr/share/puppet/modules.available/nanliu-staging/manifests/extract.pp is in puppet-module-nanliu-staging 1.0.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | # Define resource to extract files from staging directories to target directories.
define staging::extract (
$target, #: the target extraction directory
$source = undef, #: the source compression file, supports tar, tar.gz, zip, war
$creates = undef, #: the file created after extraction. if unspecified defaults ${staging::path}/${caller_module_name}/${name} ${target}/${name}
$unless = undef, #: alternative way to conditionally check whether to extract file.
$onlyif = undef, #: alternative way to conditionally check whether to extract file.
$user = undef, #: extract file as this user.
$group = undef, #: extract file as this group.
$environment = undef, #: environment variables.
$strip = undef, #: extract file with the --strip=X option. Only works with GNU tar.
$subdir = $caller_module_name #: subdir per module in staging directory.
) {
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')
} elsif $name =~ /.tar.bz2$/ {
$folder = staging_parse($name, 'basename', '.tar.bz2')
} else {
$folder = staging_parse($name, 'basename')
}
$creates_path = "${target}/${folder}"
} else {
$creates_path = undef
}
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,
}
}
if $strip {
if $::osfamily == 'Solaris' or $name !~ /(.tar|.tgz|.tar.gz|.tar.bz2)$/ {
warning('strip is only supported with GNU tar, ignoring the parameter')
$strip_opt = ''
} else {
$strip_opt = " --strip=${strip}"
}
} else {
$strip_opt = ''
}
case $name {
/.tar$/: {
$command = "tar xf ${source_path}${strip_opt}"
}
/(.tgz|.tar.gz)$/: {
if $::osfamily == 'Solaris' {
$command = "gunzip -dc < ${source_path} | tar xf - "
} else {
$command = "tar xzf ${source_path}${strip_opt}"
}
}
/.tar.bz2$/: {
$command = "tar xjf ${source_path}${strip_opt}"
}
/.zip$/: {
$command = "unzip ${source_path}"
}
/(.war|.jar)$/: {
$command = "jar xf ${source_path}"
}
default: {
fail("staging::extract: unsupported file format ${name}.")
}
}
exec { "extract ${name}":
command => $command,
}
}
|