我正在尝试在代理程序实例上创建基本目录结构。此外,我有一个define
函数用于将文件复制到代理节点。
[tom@pe-server] cat site.pp
node 'my_node' {
include base::create_dir
util::copy_files { 'Copying jar files':
source => 'puppet:///modules/java',
destination => 'c:/java_dump/test',
copy_all => 'yes',
}
}
[tom@pe-server] cat copy_files.pp
define util::copy_files ($src, $dest, $copy_all = '') {
if ($copy_all == 'yes') {
file { $dest:
ensure => directory,
source => $src,
sourceselect => all,
recurse => true,
}
} elsif {...}
}
[tom@pe-server] cat create_dir.pp
class base::create_dir (
$dir_list = $base::params::dir_list,
) inherits base::params {
$dir_list.each |$dir| {
file { $dir:
ensure => directory,
}
}
}
[tom@pe-server] cat params.pp
$dir_list = [
'c:/java_dump',
'c:/java_dump/test',
],
在代理上应用更改时,我收到以下错误:
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: {"message":"Server Error:
Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating
a Resource Statement, Duplicate declaration: File[c:/java_dump/test] is already declared in file /etc/puppetlabs/code/environments/automation/modules/base/manifests/create_dir.pp:5; cannot redeclare at /etc/puppetlabs/code/environments/automation/modules/util/manifests/copy_files.pp:17 at
/etc/puppetlabs/code/environments/automation/modules/util/manifests/copy_files.pp:17:9 at /etc/puppetlabs/code/environments/automation/manifests/site.pp:79 on node my_node"
在线搜索时,我遇到了这个link。该链接指出将公共资源移动到class
并在define
中包含该类。我不确定为什么需要它以及如何实现它。我做了以下更改:
define util::copy ($source, $destination, $copy_all = '') {
include util::copy_files
}
还在site.pp
中将util::copy_files
替换为util::copy
我现在得到的错误是:
Evaluation Error: Error while evaluating a Function Call, Class[Util::Copy_files]:\n expects a value for
parameter 'src'\n expects a value for parameter 'dest' at /etc/puppetlabs/code/environments/automation/modules/util/manifest
s/copy.pp:2:5 at /etc/puppetlabs/code/environments/automation/manifests/site.pp:79 on node my_node