On Jan 12, 4:19 pm, Sébastien Prud'homme <sebastien.prudho...@gmail.com> wrote: > The example is just there to show the duplicate problem that i don't > understand as i use a virtual ressource.
Each resource can be *declared* only once within any node's catalog, no matter whether that declaration is concrete or virtual (or exported). Virtual resources may be *realized* any number of times. In your examples, multiple invocations of your "mydefine1" are declaring the *same* (virtual) resource, hence Puppet complains. A common usage model for virtual resources is to create a class declaring all the virtual resources of a certain type that any of your nodes might want, and then have different nodes realize the ones they need. The canonical example seems to be system users; I believe the best practices document describes that. > define mydefine1 { > �...@file{ "/$name": ensure => directory } > } [...] > mydefine1 { $dir: } > realize File["/$dir"] I see that pattern sometimes, and it is NEVER useful. Specifically, it is not useful to declare a virtual resource and then immediately realize it, for that is only a more complicated way of declaring a concrete resource. Again, resource declarations may not be duplicated, virtual or not. Only *realizations* may be duplicated. > I've got a lot of mydefine2 to declare. Sure a workaround would be to > add all the mydefine1 declarations in one single class and remove it > from mydefine2 but i find it's not an elegant solution. Sorry, no help for that. Personally, I would find it inelegant to declare the same resource multiple times (even if the code were not duplicated), so I'm not bothered in the slightest that Puppet disallows it. Suppose you moved the mydefine1 calls out of mydefine2 into whatever class contains all the mydefine2 calls? That still keeps it nicely packaged together: class somefiles { define mydefine1 { ... } define mydefine2($dir) { ... } mydefine1 {"dir1": } mydefine2 { "test1": dir => "dir1" } mydefine2 { "test2": dir => "dir1" } mydefine1 {"dir2": } mydefine2 { "test3": dir => "dir2" } mydefine2 { "test4": dir => "dir2" } } YMMV, but I don't see anything inelegant about that. John
-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.