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?
You can use the ensure_resource() from stdlib module:
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.
When you have duplicate packages, that's one way of dealing with it. The other way is to avoid the problem in the first place by using virtual resources:
Declaring a virtual resource
Realizing a virtual resource (you can realize resources multiple times):
Another approach is to separate out the duplicated code into another class - i.e. a 'wget' class.
Reference: Virtual Resource Puppet Doc