What I want to do is check whether a folder has any content before copying the content in the folder, since puppet is throwing an error if you are trying to copy content of a empty folder. This is what I have tried but it doesn't work :(
exec { "Copying_patches_$setupnode-$number":
path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/bin/',
command => "cp -r ${params::script_base_dir}/libs/patches/* ${params::deployment_target}/$setup/repository/patches/",
onlyif => "test -f ${params::script_base_dir}/libs/patches/*",
notify => Notify['${params::script_base_dir}/libs/patches/* found'],
require => File["${params::deployment_target}/$setupnode"],
}
params::script_base_dir will give the path up to the script location.
Try this approach:
package { 'rsync': ensure => 'installed' }
$from = "${params::script_base_dir}/libs/patches/"
$to = "${params::deployment_target}/$setup/repository/patches/"
file { "$from/.sync_marker": ensure => file }
exec { "Copying_patches_$setupnode-$number":
path => '/usr/bin:/bin',
command => "rsync -r $from $to",
require => [
File["${params::deployment_target}/$setupnode"],
Package['rsync'],
File["$from/.sync_marker"],
],
creates => "$to/.sync_marker",
}
Some remarks:
path
- no need for java or things in /sbin
notify
resource is usually no sensible - those always produce their messagersync
, but the one on the sources does!creates
clauseThe creates
parameter makes sure that the command is run only once, and not during every run.
If you need Puppet to wait until the source directory is populated, you do have to use onlyif
. Try this condition:
onlyif => "find $from | wc -l | grep -v '^2\$'",
The two lines of output would represent the directory itself and the marker file. The $
sign is escaped so that Puppet includes it in the command string literally.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments