我试图多次调用已定义的puppet模块实例来从给定的存储库部署多个文件但我收到此错误:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: File[/bin/deploy_artifacts.rb] is already declared in file /etc/puppet/modules/deploy_artifacts/manifests/init.pp:11; cannot redeclare at /etc/puppet/modules/deploy_artifacts/manifests/init.pp:11 on node node.example.com
这是模块的init.pp清单:
define deploy_artifacts (
$repository)
{
notify{"La UUAA esta en el repositorio: $repository": }
file { "/bin/deploy_artifacts.rb":
ensure => present,
owner => root,
group => root,
mode => 700,
source => "puppet:///modules/deploy_artifacts/deploy_artifacts.rb";
}
exec {"Deployment":
require => File["/bin/deploy_artifacts.rb"],
command => "/usr/bin/time /bin/deploy_artifacts.rb $repository",
logoutput => true;
}
}
现在节点清单:
node "node.example.com" {
deploy_artifacts {'test-ASO':
repository => 'test-ASO',
}
deploy_artifacts {'PRUEBA_ASO':
repository => 'PRUEBA_ASO',
}
}
我试图重写整个模块,将常用的代码片段(文件语句)放入init.pp中,并在另一个清单中显示exec语句但是当我多次调用模块deploy_artifacts时,它会抛出相同的重复错误。
如何在执行定义的deploy_artifacts的所有实例之前重写代码以确保文件位于客户机节点中而不重复?
是否有其他解决方案而不是仅为该文件声明专用类?谢谢!
答案 0 :(得分:1)
试试这个:
文件:
class deploy_artifacts {
file { "/bin/deploy_artifacts.rb":
ensure => present,
owner => root,
group => root,
mode => 700,
source => "puppet:///modules/deploy_artifacts/deploy_artifacts.rb";
}
}
类型:
define deploy_artifacts::repository ($repository) {
include deploy_artifacts
exec {"Deployment":
command => "/usr/bin/time /bin/deploy_artifacts.rb $repository",
logoutput => true,
require => File["/bin/deploy_artifacts.rb"
}
}
节点定义:
node "node.example.com" {
deploy_artifacts::repository {'test-ASO':
repository => 'test-ASO',
}
deploy_artifacts::repository {'PRUEBA_ASO':
repository => 'PRUEBA_ASO',
}
}