我想要做的是在复制文件夹中的内容之前检查文件夹是否包含任何内容,因为如果您尝试复制空文件夹的内容,则puppet会抛出错误。这是我尝试过的,但它不起作用:(
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将提供到脚本位置的路径。
答案 0 :(得分:1)
尝试这种方法:
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",
}
一些评论:
path
- /sbin
notify
资源通常是不合理的 - 那些总是产生他们的信息rsync
无关,但是源上的斜杠确实如此!creates
子句 creates
参数确保命令仅运行一次,而不是在每次运行期间运行。
如果您需要Puppet等到填充源目录,则必须使用onlyif
。试试这个条件:
onlyif => "find $from | wc -l | grep -v '^2\$'",
两行输出代表目录本身和标记文件。 $
符号被转义,以便Puppet在字面上将其包含在命令字符串中。
答案 1 :(得分:0)
花费一些时间来找到它,这可能对其他人也有帮助
unless => "find /directory/path/ -mindepth 1 | read",
所以想要
exec { "Install wordpress in ${docroot}":
command => "git clone https://github.com/WordPress/WordPress.git ${docroot}",
unless => "find ${docroot} -mindepth 1 | read", # only cloen if directory is empty
cwd => $docroot,
path => ['/bin', '/usr/bin', '/usr/sbin'],
}