file.pp |
|
---|---|
Define: staging::fileOverview:Define resource to retrieve files to staging directories. It is intententionally not replacing files, as these intend to be large binaries that are versioned. Notes:If you specify a different staging location, please manage the file resource as necessary. Parameters:
Usage:
|
define staging::file (
$source,
$target = undef,
$username = undef,
$certificate = undef,
$password = undef,
$environment = undef,
$timeout = undef,
$subdir = $caller_module_name
) {
include staging
if $target {
$target_file = $target
$staging_dir = staging_parse($target, 'parent')
} else {
$staging_dir = "${staging::path}/${subdir}"
$target_file = "${staging_dir}/${name}"
if ! defined(File[$staging_dir]) {
file { $staging_dir:
ensure=>directory,
}
}
}
Exec {
path => '/usr/local/bin:/usr/bin:/bin',
environment => $environment,
cwd => $staging_dir,
creates => $target_file,
timeout => $timeout,
logoutput => on_failure,
}
case $source {
/^\//: {
file { $target_file:
source => $source,
replace => false,
}
}
/^puppet:\/\//: {
file { $target_file:
source => $source,
replace => false,
}
}
/^http:\/\//: {
exec { $target_file:
command => "curl -L -o ${name} ${source}",
}
}
/^https:\/\//: {
if $username {
$command = "curl -L -o ${name} -u ${username}:${password} ${source}"
} elsif $certificate {
$command = "curl -L -o ${name} -E ${certificate}:${password} ${source}"
} else {
$command = "curl -L -o ${name} ${source}"
}
exec { $target_file:
command => $command,
}
}
/^ftp:\/\//: {
if $username {
$command = "curl -o ${name} -u ${username}:${password} ${source}"
} else {
$command = "curl -o ${name} ${source}"
}
exec { $target_file:
command => $command,
}
}
default: {
fail("stage::file: do not recognize source ${source}.")
}
}
} |