[chef] Re: LWRP to extend a Chef resource?


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: LWRP to extend a Chef resource?
  • Date: Tue, 29 Oct 2013 08:18:31 -0700

On Tuesday, October 29, 2013 at 8:10 AM, Mike wrote:
I've been looking in to how I might go about writing something to subclass an existing Chef resource, that already extends another Chef resource.

Case: the easy_install_package resource subclasses the package resource, and adds semantics and behavior specific to easy_install.

I want to further subclass this resource and add some defaults, so that whenever I call mikes_easy_install_package (name is WIP) I get the directives/options I've declared.

Is there a decent example of this anywhere, and my Google-fu is simply failing me today?

Thanks,
-Mike
Because of the way the LWRP DSL abstracts the class definition, you can’t specify a superclass when you create a LWRP. We looked at one workaround for this, but it had some drawbacks and compatibility issues.

Long term (like Chef 12.0), we’re considering modifying the way LWRPs are defined to make this possible, but for now it isn’t. The best you can do is wrap the existing resource/provider, like

# code in your provider
action(:install)
  easy_install_package(name) do
    default_setting_1 “hardcoded value”
    default_setting_1 “hardcoded value”
    dynamic_setting new_resource.dynamic_setting
  end
end

If that doesn’t work, you might need to write a “heavy weight” resource or provider using regular ruby code. The runit cookbook is one example of how to do this (look in the libraries dir).  https://github.com/opscode-cookbooks/runit

-- 
Daniel DeLeo




Archive powered by MHonArc 2.6.16.

§