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


Chronological Thread 
  • From: Loïc Antoine-Gombeaud < >
  • To:
  • Subject: [chef] Re: Re: Good example of a lwrp
  • Date: Wed, 5 Dec 2012 13:41:26 +0100

Hello all,

I'm starting to implement my own LWRPs as well, and in addition to reading existing implementations as suggested by Joshua, I found the Wiki page to be quite helpful in understanding what they were, and how they contrast with "heavy-weight" resources and providers:
http://wiki.opscode.com/display/chef/Lightweight+Resources+and+Providers+(LWRP)
It was officially moved to the Chef Docs just 3 weeks ago, so I'm guessing the code examples of the Wiki (which are absent from Chef Docs) should remain valid for a little while.

Best,

Loïc

On Fri, Nov 30, 2012 at 6: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





--
Loïc ANTOINE-GOMBEAUD
IT Engineer I
Plinga GmbH | www.plinga.com
Saarbrücker Straße 20/21 | 10405 Berlin | Germany

E-Mail: " target="_blank"> | Skype:loic.plinga
Telefon : +49(0)160-92286573

Geschäftsführer: Johannes Kreibohm, Florian Schmidt-Amelung
Eingetragen beim Amtsgericht Charlottenburg, HRB 119994




Archive powered by MHonArc 2.6.16.

§