How to extend a light supplier in a chef

I am creating a bunch of different chef vendors to deploy different types of applications. The chef's documentation for Expand Lightweight Provider suggests that this is possible, but does not really say what to do. This page suggests that you may need a call mixin, but I don’t know what structure my code should have in the file under /libraries, or how to actually include this code in something under /providers.

Here are examples of what I want to do.

In my 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 my provider for deploying Torquebox Rails applications:

deploy_revision "/my/deployment/directory/#{deployment[:project]}" do
  # Magically mixin the code from libraries
  environment "RAILS_ENV" => node[:chef_environment]
  restart_command "rake torquebox:deploy"
end

And, of course, other types of providers for different types of applications.

Can someone point me in the right direction? Is there documentation somewhere I am missing?

+5
1

- LWRP DSL Ruby . , ( , ).

, bacon LWRP bacon/resources/eat.rb, LWRP bacon_eat. - - Chef::Resource::BaconEat Chef::Provider::BaconEat .

- default. " " -, . , bacon LWRP bacon/resources/default.rb, LWRP bacon ( bacon_default). - , - Chef::Resource::Bacon Chef::Provider::Bacon ( "BaconDefault" ) .

, ? LWRP, LWRP (Rubyism). libraries/ :

class Chef
  class Resource::MyResource < Resource::Bacon # <- this
  end
end

, :

class Chef
  class Resource::MyDeployRevision < Resource::DeployRevision
    def initialize(name, run_context = nil)
      super

      # This is what you'll use in the recipe DSL
      @resource_name = :my_deploy_revision

      # Things like default action and parameters are inherited from the parent

      # Set your 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

my_deploy_revision .

+7

All Articles