I have been googling around to find an answer but was not able to find it.

I have created my own custom type in puppet. According to the documentation 
here Puppet Resource Types manual 
<https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource_types.md>.
 
This type creates a config file and in it I would like to add as comment 
lines information from where the resource is called/created.

I want to get the filename, classname, linenumber of the puppet class and 
pp file calling this custom type (resource)?

I know in Ruby I can use the "caller" function/variable/object to get a 
stack trace. But when I do this in my custom type I get a stack trace from 
Ruby and not Puppet.

For example I have the following code:

# File my_module/manifests/my_module.pp
class my_module{

  my_module_type( {'aname':;}
}

# File my_module/lib/puppet/type/my_module_type.pp
Puppet::Type.newtype(:my_module_type) do
  newparam(:trace) do
    defaultto caller.inspect
  end
end

So "caller.inspect" produces:

["/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/classgen.rb:136:in 
`class_eval'", 
"/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/classgen.rb:136:in 
`genthing'", 
"/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/classgen.rb:36:in 
`genclass'", 
"/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:459:in 
`newparam'", 
"/vagrant/site/my_module/lib/puppet/type/my_module_type.rb:69:in `block in 
<top (required)>'", 
"/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/classgen.rb:136:in 
`c...]

It nicely shows a stack trace of the different puppet ruby files used. But 
what I would like is something like:

[ my_module/manifests/my_module.pp:3:in "class my_module", .....]

Is this possible? If so how?

Regards,

Michel.


-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/cef67564-c584-4014-b21b-df28308418a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to