> http://docs.puppetlabs.com/guides/modules.html <-- I guess you want to
> define your own module.
Yup, did that already.
The answer I was looking for is this.
Given: we want a custom type my_cool_type such that we can write
my_cool_type { "bla":
justsometext => "hi mom",
source => "puppet:///modules/six/file.txt",
}
To make a source parameter in this custom type which will fetch the
given content, do something like so:
Puppet::Type.newtype(:my_cool_type) do
ensurable do
defaultvalues
defaultto :present
end
newparam(:justsometext) do
desc "A string of your choosing."
end
newparam(:source) do
[Now copy the validate, munge, cached_attr(:content), and
cached_attr(:metadata) from puppet/type/file/source.rb in here.]
end
end
In the provider, it's usual to get at the parameter values like
@resource[:paramname]. This will get us the value of the justsometext
parameter:
Puppet::Type.type(:my_cool_type).provide :strange_magic do
def create
self.debug "The string of the admin's choosing was
#{@resource[:justsometext]}."
end
end
But @resource[:source] is just the puppet:/// url. It's supposed to have
this content method; how do we call that? Answer: @resource[:source] is
a shortcut for @resource.parameter(:source).value.
@resource.parameter(:source) gets the parameter object, upon which we
can call the content method.
def create
self.debug "The contents of file.txt are
#{@resource.parameter(:source).content}"
end
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" 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-users?hl=en.