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


Chronological Thread 
  • From: Ranjib Dey < >
  • To:
  • Subject: [chef] Re: Re: Re: good example of chef definitions ? need help with issue below
  • Date: Fri, 4 Oct 2013 12:38:03 -0700

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"> > 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"> > 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"> > 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





Archive powered by MHonArc 2.6.16.

§