On Wednesday, February 14, 2018 at 12:02:41 PM UTC-6, Peter Bauer wrote: > > hi, > > i was recently bitten by ordering issues caused by missing contain/anchor > declarations in a PostgreSQL module which should have finished its job > before configuring and starting the PuppetDB which is done by another > module. > So here are my questions: > - is it possible to use the contain function also for defined resource > types/defines? I ended up using anchors since i could not find out how to > use contain here. >
Resources, whether of defined or plugin type, are automatically contained by the object that declares them. You don't need to use contain, anchors, or any other special measure to make that happen. Containment needs to be explicitly managed only for classes. On the other hand, it generally does not make sense for a resource instance to contain a class, because classes are singletons. If a resource (of a defined type) contained a class, then all resources of the same type would need to have overlapping containment, which often is not possible (and whose feasibility in practice is typically unpredictable). Therefore, although it sometimes makes sense for a defined type to include or even require a class, if you think containment is warranted then convert the defined type into a class itself. > - am i the only one thinking that it is too error-prone and cumbersome to > add a contain everytime a sub-class is instantiated in a module? Since it > is not transitive it has to be added on every abstraction layer of a > module, from the init.pp down to all sub-classes until there are just > classes left declaring resources directly. And in case one contain is > missing, that code may be executed in the wrong time. > If you really mean "sub-class" in the class inheritance sense, then either your Puppet usage is highly suspect or your terminology is. I suspect you just mean "class", or maybe "module class" if you want to emphasize that the class in question belongs to the same module as the one declaring it. Do not mistake Puppet DSL for an object-oriented language along C++ lines. The DSL is object oriented in its own fashion, but Puppet's "classes" are not very analogous to C++'s. Anyway, it is an intentional design feature that classes are not automatically contained by the object that declares them. This follows necessarily from the fact that classes can be declared multiple times in different scopes. If containment were automatic then exercising that multiple-declaration freedom would rapidly create unresolvable dependency cycles. Inasmuch as you complain about multiple layers, I'm inclined to suspect that your problems are partly attributable to your approach to module design. A module with deeply nested containment has bad code smell to me, so consider flattening. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2d22abaf-2f18-4323-a625-b56bf54da219%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.