How to extend a lightweight provider in Chef -


i creating bunch of different chef providers deploy different types of applications. chef's documentation extend lightweight provider suggests possible doesn't do. page suggests perhaps call mixin needed, don't know structure code should have in file under /libraries or how include code in under /providers.

here examples of want do.

in base class under /libraries:

repository "http://my.svn.server/#{deployment[:project]}/branches/#{node[:chef_environment]}/" user "deploy" scm_provider chef::provider::subversion svn_username "svn_user" svn_password "password" 

in provider torquebox rails app deployments:

deploy_revision "/my/deployment/directory/#{deployment[:project]}"   # magically mixin code libraries   environment "rails_env" => node[:chef_environment]   restart_command "rake torquebox:deploy" end 

and of course other types of providers different types of applications.

can point me in right direction on this? there documentation somewhere i'm missing?

the chef automatically convert lwrp dsl full-blown ruby class @ runtime. determined name of cookbook followed name of file (this same way actual resource name created).

so if have cookbook named bacon , lwrp in bacon/resources/eat.rb, associated lwrp bacon_eat. associated class camel-cased, constantized version of - chef::resource::baconeat , chef::provider::baconeat in case.

there 1 exception pattern - default. "default" special in chef land, doesn't prefixed. if have cookbook named bacon , lwrp in bacon/resources/default.rb, associated lwrp bacon (not bacon_default). associated class camel-cased, constantized version of - chef::resource::bacon , chef::provider::bacon (not "bacondefault") in case.

okay, why backstory? in order extend lwrp, want inherit lwrp's class (rubyism). in libraries/ directory, want extend custom resource:

class chef   class resource::myresource < resource::bacon # <-   end end 

so, in example:

class chef   class resource::mydeployrevision < resource::deployrevision     def initialize(name, run_context = nil)       super        # you'll use in recipe dsl       @resource_name = :my_deploy_revision        # things default action , parameters inherited parent        # set default options here       @repository = "http://my.svn.server/#{node['deployment']['project']}/branches/#{node.chef_environment}/"       @user = 'deploy'       @scm_provider = chef::provider::subversion       @svn_username = 'svn_user'       @svn_password = 'password'     end   end end 

then use my_deploy_revision in recipes.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -