[chef] Re: Re: Good example of a lwrp


Chronological Thread 
  • From: Maven User < >
  • To: chef < >
  • Subject: [chef] Re: Re: Good example of a lwrp
  • Date: Thu, 20 Dec 2012 12:53:07 -0500

Sorry to dredge this old thread back up - but I've followed the examples I see above and combined that with the docs and I'm struggling a bit (still).

In my lwrp, for now - I have a default provider (default.rb) and a default resource (default.rb).

Then in the cookbook where I want to leverage this lwrp, I have something like this:

my-lwrp-name "somename" do
  action :install
  attributename "somevalue"
end

but this generates an error syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' my-lwrp-name "somename" do

It's like it doesn't want "somename".

Also - its kinda unclear - if the cookbook that is trying to leverage this lwrp is setting attributes, how do you reference those in your provider, new_resource.<attributename>?






On Fri, Nov 30, 2012 at 12:32 PM, Joshua Timberman < " target="_blank"> > wrote:
Ohai,

On 11/30/12 9:31 AM, "Maven User" < "> > wrote:

>I'm still on my quest to simplify our deployments and was wondering if
>there is a good demo/example/sample I can look at to create my own LWRP?
>
>I can see how to create the resource, but the provider bit is kinda
>confusing.

First, LWRPs are specifically the lightweight DSL that doesn't require the
ruby class structure. "Heavyweight" resources/providers are like the ones
that come with Chef itself. The "database" cookbook implements its
resources/providers as heavyweight due the way that the LWRPs are
automatically named by the cookbook and the filenames, and we wanted to
name

Second, the key is to make your resources idempotent. This is easy if
you're using resources inside the action blocks in the provider, and the
examples (below) have some of that. In some cases, like when you're
chaining together a bunch of command execution, you'll want to use
"load_current_resource" to check the current state of the system.

There are more advanced considerations, such as why-run support, and
handling updated resources, but for now stick to a simple use case.

These LWRPs from Opscode's cookbooks are relatively simple examples:

https://github.com/opscode-cookbooks/cron/blob/master/providers/d.rb

https://github.com/opscode-cookbooks/samba/blob/master/providers/user.rb

https://github.com/opscode-cookbooks/daemontools/blob/master/providers/serv
ice.rb


As an exercise, I'd probably start by doing an LWRP that simply handles
dropping off a "conf.d" style of configuration file.

Hope this helps!

--
Opscode, Inc
Joshua Timberman, Technical Community Manager
IRC, Skype, Twitter, Github: jtimberman






Archive powered by MHonArc 2.6.16.

§