问题原文
原帖链接 · Tombart · CC BY-SA 3.0
When defining dependencies in a class each Package can be globally defined just once. I have hierarchy of configuration and some packages should be installed on all machines (that goes to default configuration) but other should be installed only on some category of machines. How I am supposed to check whether that package is already on a machine when Puppet threat is as a duplicate declaration?
Duplicate declaration: Package[wget] is already declared
should I use a function like this?
if defined( Package[$package] ) {
debug("$package already installed")
} else {
package { $package: ensure => $ensure }
}
I would expect from configuration tool to deal whith this issue by default... am I missing something?
已采纳解答
原帖链接 · synapse · CC BY-SA 3.0
You can use the ensure_resource() from stdlib module:
$packages = $::osfamily ? {
'Debian' => [ 'fcgiwrap', ],
'RedHat' => [ 'spawn-fcgi', 'git' ],
}
ensure_resource('package', $packages, {'ensure' => 'present'})
So, say, if git is installed by some other class already, that would be skipped. You should not care of defining a package only once throughout the puppet configuration.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
