Puppet - 测试包是否已经定义? [英] Puppet - test if a package already defined?
本文介绍了Puppet - 测试包是否已经定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一些 puppet 模块,并且在两个模块中定义了一个包,因此出现以下错误:
I'm writing some puppet modules and have a package defined in two modules hence get the following error:
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate definition: Package[gnome-session-fallback] is already defined in file /etc/puppet/modules/vnc4server/manifests/init.pp at line 3; cannot redefine at /etc/puppet/modules/vino/manifests/init.pp:7 on node l
因此要确保包尚未定义,但以下内容不起作用:
Hence want to ensure that the package has not already been defined but the following does not work:
if ! defined ('gnome-session-fallback') {
package { 'gnome-session-fallback':
ensure => installed,
}
}
谁能建议如何解决这个问题,在更广泛的范围内,避免模块中此类冲突的正确"方法是什么?
Can anyone suggest how to fix this, and on the broader scale, what is the "proper" approach to avoiding clashes such as this in modules?
推荐答案
您在 defined() 中缺少 Package[].正确的做法:
You are missing Package[] inside defined(). The correct way to do it:
if ! defined(Package['gnome-session-fallback']) {
package { 'gnome-session-fallback':
ensure => installed,
}
}
这篇关于Puppet - 测试包是否已经定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文