[chef] RE: Re: Re: Re: Re: good example of chef definitions ? need help with issue below


Chronological Thread 
  • From: Kevin Keane Subscription < >
  • To: < >
  • Subject: [chef] RE: Re: Re: Re: Re: good example of chef definitions ? need help with issue below
  • Date: Fri, 4 Oct 2013 22:56:00 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=sendgrid.info; h=subject:from:to:mime-version:content-type:in-reply-to:references:sender; q=dns; s=smtpapi; b=hYXK3REDVde5vyUcJ+Phg47pKz2oy4qg2vRbdPdM00Hc FxeTqvtiS0wS9+o4zSIUBDCfD4uP4eQxtglDXKnimXX4T7qOPMg+K0TR2Q6Fwf3g 8XYEiGEtH71lp64sNFw0wFj9ByzeXDaDsJ8aSZCDaEXZakFxbgMrIxes7GNV21c=

Title: RE: [chef] Re: Re: Re: Re: good example of chef definitions ? need help with issue below

Think interface (resource) vs. implementation (provider)

First, you need to define what the LWRP should actually be able to do, which actions it should support, etc.

In your example, you could create a resource called warfile. In your cookbook, create a file resources/warfile.rb that contains something like this:

def initialize(*args)

  super

  # initialize any attributes your LWRP has

end

action :deploy

attribute :name, :kind_of => String, :name_attribute => true

# You may need additional attributes, for instance to control permissions, URLs, or anything else that needs to be configurable during your deployment.


Next, you'd create the corresponding provider, in a file providers/warfile.rb . That's where you implement each of your actions, in pretty much plain ruby (but you can embed resources):

action :deploy do

  # download and unzip the files, create your link, etc., either in Ruby code or using cookbook_file, remote_file etc. resources.

end




Kevin Keane

The NetTech

760-721-8339

http://www.4nettech.com

Our values: Privacy, Liberty, Justice

See https://www.4nettech.com/corp/the-nettech-values.html


-----Original message-----
From: Manoj Thakkar < >
Sent: Friday 4th October 2013 14:05
To:
Subject: [chef] Re: Re: Re: Re: good example of chef definitions ? need help with issue below

Thanks a lot everyone,

to me writing LWRP is a tedious job, or the documentation is not enough to make it easier for me,

Can anyone please help me refactor the recipe below in resource and provider, I am sorry if its too much to ask for, it will at least help me write the next one myself.

cookbook_file "#{node[:tcat][:base_dir]}/webapps/#{node[:tcat][:war_name]}.war" do
  source "#{node[:tcat][:war_name]}-#{node[:file][:version]}.war"
  mode 0777
  owner "deploy"
  group "deploy"
end
remote_file "#{node[:tcat][:base_dir]}/#{node[:tcat][:env]}-config.zip" do
  source "http://abc-data-dev.com.zip&v=LATEST"
  mode '777'
  owner "deploy"
 notifies :run,  "bash[unzip_file]", :immediately
end

bash "unzip_file" do
   cwd "#{node[:tcat][:base_dir]}"
   code <<-EOS
   pwd
   unzip "#{node[:tcat][:env]}-config.zip"
   EOS
  action :nothing
end

link "#{node[:tcat][:base_dir]}/zak-config" do
  to "#{node[:tcat][:env]}-config"
end


On Fri, Oct 4, 2013 at 12:38 PM, Ranjib Dey < " target="_blank" title="This external link will open in a new window"> > wrote:
i dont think anyone should use definition, iirc a debate where we were discussing deprecating them (or at least not advocating them), as steve pointed out, they are more like macro expansion, but since chef run is dual phases, macro expansion has subtle consequences. they pretty much blocks building higher abstraction on top of them.

Consider this,  you want is to write an abstraction using aggregated ( 1 template, 1 service , couple of other resources). You can add a standard ruby method in a library to do this. you can make a definition . or you can make a resource. Now only the last option will give you full strengths (like notifications, why run, use_inline_mode etc), you might not need them, but why impose such restrictions anyway, given basic lwrp development is as simple as writing a definition (i think definitions are more code that their equivalent lwrp, but thats me)

best
ranjib


On Fri, Oct 4, 2013 at 10:06 AM, steve . < " target="_blank" title="This external link will open in a new window"> > wrote:
My two cents:

When asking yourself if you should use a definition, remember that it's a macro.  You may invoke it like a resource, but it is not a resource.  Are you only looking to save yourself some typing or are you looking to do something more?

If all you want to do is blast 26 Java apps out in the same way onto a node, you could do that with a macro.  So a define's probably a good fit for that.

If you are looking to ultimately _manage_ those apps (and, say, have their config file changes trigger redeploys/restarts), but right now you just need to deploy them, you might want to consider throwing all that into a LWRP (or HWRP, if you fear not the Ruby).  You'll probably end up doing it eventually anyway, so you might as well start as you mean to go on.


On Fri, Oct 4, 2013 at 1:42 AM, Andy Gale < " target="_blank" title="This external link will open in a new window"> > wrote:
Good example of a definition here :) 


LWRPs are where it's at nowadays though definitions are a bit easier to understand I think.

If people feel strongly about it though, convert that to a LWRP and I'll be happy to update the book!


On Fri, Oct 4, 2013 at 8:24 AM, Manoj Thakkar < " target="_blank" title="This external link will open in a new window"> > wrote:
Hi,

I am looking for some good example for chef definition,  or may be someone can help me change my recipe in to a definition so that i can use it in any recipe.

* this is the use case , i have this tomcat web deployment for 10+ wars since the deployment mechanism remains the same for every war i think a definition is the right thing to do, correct me if i am wrong

here is my recipe  .Please help change it to a definition and a use case on how to sue it

cookbook_file "#{node[:tcat][:base_dir]}/webapps/#{node[:tcat][:war_name]}.war" do
  source "#{node[:tcat][:war_name]}-#{node[:file][:version]}.war"
  mode 0777
  owner "deploy"
  group "deploy"
end
remote_file "#{node[:tcat][:base_dir]}/#{node[:tcat][:env]}-config.zip" do
  mode '777'
  owner "deploy"
 notifies :run,  "bash[unzip_file]", :immediately
end

bash "unzip_file" do
   cwd "#{node[:tcat][:base_dir]}"
   code <<-EOS
   pwd
   unzip "#{node[:tcat][:env]}-config.zip"
   EOS
  action :nothing
end

link "#{node[:tcat][:base_dir]}/cas-config" do
  to "#{node[:tcat][:env]}-config"
end





--
Andy Gale
http://andy-gale.com
http://twitter.com/andygale





  • [chef] RE: Re: Re: Re: Re: good example of chef definitions ? need help with issue below, Kevin Keane Subscription, 10/04/2013

Archive powered by MHonArc 2.6.16.

§