On May 11, 2010, at 11:36 AM, Richard Crowley wrote:
I'm looking at building a simple ensurable custom type that itself
uses Puppet resources to manage a group of files and users. Because
of the multi-dimensional data structures I'm dealing with, dropping
into Ruby seems to be the best way to go. I have a feeling that using
file resources is the right way to do this but I'm having trouble with
providers. First, I'm just trying to get it to run without exceptions
using the following type and provider:
require 'puppet/type'
Puppet::Type.newtype(:foobar) do
@doc = "foobar"
newparam(:name, :namevar => true) do
desc "foobar name."
end
ensurable do
self.defaultvalues
defaultto :present
end
end
require 'puppet/resource'
require 'puppet/resource/catalog'
require 'puppet/type'
require 'puppet/type/file'
require 'puppet/type/user'
Puppet::Type.type(:foobar).provide(:posix) do
desc "foobar"
defaultfor :operatingsystem => :debian
def create
Puppet.notice :create
catalog = Puppet::Resource::Catalog.new
catalog.add_resource Puppet::Resource.new(:user, "demo", :ensure
=> :absent)
catalog.apply
end
def destroy
Puppet.warn "DevStructure users should never need to be destroyed."
end
def exists?
Puppet.notice :exists?
false
end
end
The error is: "err: Got an uncaught exception of type NoMethodError:
undefined method `provider' for #<Puppet::Resource:0x7f1f8f724b78>"
(Full output below.)
The probem seems to be in setting/inheriting the default provider for
the user resource. How does the main catalog set/inherit default
providers? Is this use of resources advisable/supported or would I be
best off not using a catalog or not using resources altogether?
The confusion here is that we're kind of mid-transition in the system
right now - we haven't yet completely transitioned to using
Puppet::Resource. You need to be creating an instance of a 'user'
resource class:
user = Puppet::Type.type(:user).new(:name => "demo", :ensure
=> :absent)
Also, you probably just want to put this in a 'generate' method on
your resource, rather than in the provider like you have it.
Something like:
require 'puppet/type'
Puppet::Type.newtype(:foobar) do
@doc = "foobar"
newparam(:name, :namevar => true) do
desc "foobar name."
end
ensurable do
self.defaultvalues
defaultto :present
end
def generate
Puppet::Type.type(:user).new(:name => self[:name], :ensure
=> :absent)
end
end
Or something similar.
--
In science, 'fact' can only mean 'confirmed to such a degree that it
would be perverse to withhold provisional assent.' I suppose that
apples might start to rise tomorrow, but the possibility does not
merit equal time in physics classrooms. -- Stephen Jay Gould
---------------------------------------------------------------------
Luke Kanies -|- http://puppetlabs.com -|- +1(615)594-8199
--
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.