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. 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.