- From: Joshua Timberman <
>
- To: "
" <
>
- Subject: [chef] Re: Good example of a lwrp
- Date: Fri, 30 Nov 2012 17:32:41 +0000
- Accept-language: en-US
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.