On Wednesday, April 24, 2013 7:28:55 AM UTC-5, Patricia Jung wrote: > > Hello Puppeteers, > > please consider the following scenario: Puppet is supposed to set up > similar (but not necessarily identical) groups of hosts for a range of > customers. For each customer a dedicated filesystem tree needs to be > established on host A. >
I'm not sure I follow, but I think you mean "host A" a designated special node somewhere. It's not clear whether that's one of the hosts in a per-customer group, but maybe that doesn't matter. > > This should not be difficult using exported File resources, however: How > do I make sure that only the exported File resource of the first created > host in a customer group is imported by host A? Otherwise puppet will -- > understandably -- complain about duplicate imported resources on host A: > > Error: Another local or imported resource exists with the type and title > File[customer/fs/tree] on node A > > In other words: May I use an "if defined()" when collecting resources on > host A -- and if so: How does the syntax to reference a specific _imported_ > resource look like? No, you can't, and if you could then you would be better off not to do. Do not use defined(). Ever. You may have a misconception about what exported are or how they work. Exported resources provide a means to declare a resource during compilation of one node's catalog that can later be incorporated by reference into one or more other nodes' catalogs. What does it mean, however, if multiple nodes export the same resource? Although there are ways by which particular ones can be selected (see below), such a collision usually reflects a design error. If all the exported declarations are the same, then they must not contain any node-specific information. In that case, what was the purpose of exporting / importing? It would be simpler and better in that case to just declare the needed resources directly on the target host. On the other hand, if the declarations differ, and you only want to import one of them, then why does it make sense to export all of them? With that said, you can use a selection predicate when you collect resources to filter the resources to collect (http://docs.puppetlabs.com/puppet/3/reference/lang_collectors.html). Selection predicates can test only the parameters of the exported resources, however, not (directly) the node that exported them. To apply this to your case there would need to be some per-host unique parameter carried by the exported resources by which you would select. If nothing else presents itself, then perhaps that could be the 'tag' metaparameter. > Or would I be able to prevent the creation of an exported File resource on > a customer host when host A already has imported the appropriate resource > from a host previously defined for this customer? (In this case: How do I > reference "File[customer/fs/tree] on node A"?) > Not easily, though you could probably create a custom function, or maybe even a custom fact, to do this. But don't bother: it won't reliably achieve your aim because it's not safe to assume that node A will be synced between the first host in a customer group and all the rest of them. That is, whether node A has *imported* a resource is not a reliable indication of whether any node has *exported* that resource. > > There's no way to tell which host type in a customer group will be created > first (all customers will have at least one host, but not necessarily of > the same type), hence I can't pin the exported File resource to a certain > type of host which always has to be installed first. > > Or should I consider a completely different approach to solve the problem > -- any suggestion which one? > > It sounds to me like exported resources are the wrong solution to this problem. What prevents you from declaring the needed filesystem trees as ordinary resources declared for node A? 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.