I have a puppet custom type in /etc/puppet/modules/tipo/lib/puppet/type/customtipo.rb which contents are:
require 'logger'
Puppet::Type.newtype(:customtipo) do
newproperty(:parametro) do
log.info("ES UN PARAMETRO")
end
end
I know that is a dummy custom type but I'm starting with this sort of things, the resource is placed in /etc/puppet/modules/tipo/manifests/init.pp which contents are:
class tipo {
customtipo {
"ejemplo":
parametro => "uno",
}
}
The case is whether is a "parametro" or not it doesn't show the message "ES UN PARAMETRO" as I could expect. Is there some other way to achieve this using a custom type? Thanks!
Note that the log
command will run when your type is loaded by the Ruby runtime, not when the compiler encounters a resource of your type.
Also note that Puppet has a logging framework of its own in Puppet::Util::Logging
, that is mixed into any type. You can always just Puppet.info
or Puppet.debug
.
To get an idea of how to debug your type code, you should familiarize yourself with the available hooks. Look at existing types in Puppet's own source code. You could start with something like this:
Puppet::Type.newtype(:customtipo) do
newparam(:parametro) do
# no actual validation, just logging to get started
validate do |value|
Puppet.info("parameter 'parametro' has value '#{value}'")
end
end
end
Note that I changed newproperty
to newparam
because you don't want to have a property that is named "parameter". That would be way confusing.