On Tuesday, March 6, 2012 at 10:03 AM, Trevor Vaughan wrote:
> Sorry about the re-post, but I'm not getting much traction in the User's list.
> 
> So, many moons ago, the following used to work:
> 
> require 'puppet'
> 
> Puppet::Parser::Functions::function(:mangle_ip_address)
> s = Puppet::Parser::Scope.new
> # Mask the ipaddress variable
> s.setvar('ipaddress','11.22.33.44')
> s.mangle_ip_address
> 
> However, now that we have to call 'lookupvar' in our functions, this
> doesn't work and gives the error:
> 
> NoMethodError: undefined method `known_resource_types' for nil:NilClass
>        from 
> /usr/lib/ruby/site_ruby/1.8/puppet/resource/type_collection_helper.rb:5:in
> `known_resource_types'
> 
> Does anyone have any ideas on how to get this working again?
> 
It looks like it's trying to look up a class to check if a variable is in 
there, so it needs a TypeCollection (known_resource_types) which comes from an 
environment. It should work to just create an environment and stub it on the 
scope (unfortunately, it normally comes from compiler, so you can't just set 
it, but there's no reason to actually make a compiler).

env = Puppet::Node::Environment.new('nodename')
s = Puppet::Parser::Scope.new
s.stubs(:e).returns env
> 
> Thanks,
> 
> Trevor
> 
> --
> Trevor Vaughan
> Vice President, Onyx Point, Inc
> (410) 541-6699
> [email protected] (mailto:[email protected])
> 
> -- This account not approved for unencrypted proprietary information --
> 
> -- 
> 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