On 24/08/11 14:09, jcbollinger wrote:
On Aug 24, 4:54 am, Jonathan Gazeley<[email protected]> wrote:Hi, Sorry if this is a basic question, but I can't find the answer in the docs. I know about fully-qualified variables, but how can I reference a type that is defined in a different class, so I can require/subscribe it? In this simple example, what's the right syntax for making goodbye.txt require hello.txt? class class1 { file { "hello.txt" } } class class2 { file { "goodbye.txt": require => File['hello.txt'], } }The word you are looking for is "resource," not "type." The latter is more likely to make people think of user-defined resource types, such as are declared via the "define" statement. The answer is that resource titles and names are global (and must be globally unique) in nodes' catalogs, therefore you don't have to use any special syntax to reference a resource from outside the scope where it is declared. You do, however, need to ensure that the declaration is visible at the point of reference. As long as you're not using parameterized classes, the best way to do that is via the "include" statement, like so: class class1 { file { "hello.txt" } } class class2 { # Include the class declaring File['hello.txt'] include "class1" file { "goodbye.txt": require => File['hello.txt'] } } Do remember that Puppet's "include" statement is *not* analogous to, for example, the C peprocessor's "#include" directive. It does not cause any code interpolation; instead, "include" tells Puppet that the specified class must be included in the current node's catalog. John
Thanks for your excellent response. I hadn't realised that resource names were global, nor that "include" behaves differently from that of the C preprocessor. Win on both counts - I've got my manifest working.
Thanks a lot, Jonathan -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
