On Monday, July 23, 2012 at 9:45 AM, Matthew Probst wrote:
> Is it possible to do the following?
> 
> Create a function foo that returns a list of references to existing
> objects.
> 
> One would call, say
> 
> realize(foo())
> 
> or
> 
> some_type { "some_name":
> .
> .
> require => foo()
> }
> 
> and foo would return the equivalent of
> 
> [ File['bar'], File['baz'], File['quux'] ]
> 
> which would be consumed by the realize function or by the require
> metaparameter. It's possible these are two separate cases requiring
> different code, which I'd still be interested in finding out about.
> But syntactically it appears they are just lists of references that
> get flattened somewhere.
> 
> I've been looking for documentation but the official name for these
> references is "object references" (mentioned on the Puppet
> "metaparameters" page under the require metaparameter) and searching
> for "puppet object references" in combination with "custom function"
> just doesn't return anything that I'm familiar with.
> 
> The point I'm most interested in, is how would one create an object
> reference to some resource already defined in the manifest, such as
> File['bar'], from a custom function written in Ruby. I have
> successfully written and debugged custom functions that _don't_ need
> to do this.
> 
> I find examples of how to create a brand new file object, but not how
> to refer to an existing one, in the form used by the require
> metaparameter and the realize function
> 
> 


Generally speaking, Puppet language deals in strings. In particular, function 
arguments are usually strings, even though they may have other meaning. You 
should be able to just use the string "File[bar]" to refer to the resource 
File[foo]. For the most part, resource references and the strings that look 
like them are used interchangeably:

realize(File[foo])
realize("File[foo]")

However, just as with numbers (which are also typically represented as 
strings), any internal piece of Puppet that actually cares about dealing with 
resource references will eventually need to convert it. The Puppet-Ruby barrier 
may not always be crossed properly, so do proceed with caution.

If you're writing your own functions, you're more in control of your own 
destiny in that way. You can get a resource reference by calling 
findresource("File[foo]").
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Puppet Developers" group.
> To post to this group, send email to [email protected] 
> (mailto:[email protected]).
> To unsubscribe from this group, send email to 
> [email protected] 
> (mailto:[email protected]).
> For more options, visit this group at 
> http://groups.google.com/group/puppet-dev?hl=en.
> 
> 


-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" 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-dev?hl=en.

Reply via email to