[chef] Re: Re: Re: Re: How does chef keep state to skip the recipe from running multiple time


Chronological Thread 
  • From: Todd Michael Bushnell < >
  • To:
  • Cc:
  • Subject: [chef] Re: Re: Re: Re: How does chef keep state to skip the recipe from running multiple time
  • Date: Sun, 10 Mar 2013 03:06:31 -0700

Howard,

If indeed you are talking about what Lusis is referring to: a recipe that runs one time and removes itself from the run_list, here's a cookbook with that functionality:

The relevant code is in recipes/default.rb:

ruby_block "remove annoyances from run list" do
  block do
    node.run_list.remove("recipe[annoyances]")
  end
  only_if { node.run_list.include("recipe[annoyances]") }
end

I actually found myself using similar logic in a bootstrap recipe that I recently wrote.  Probably won't use it often, but nice to know about it when you do.  Cheers!

:: toddmichael


On Mar 10, 2013, at 12:52 AM, John E. Vincent (lusis) wrote:

On Sun, Mar 10, 2013 at 1:34 AM, howard chen < "> > wrote:
Hi,


On Sun, Mar 10, 2013 at 2:07 PM, Jeffrey Hulten < "> > wrote:
Are you talking between multiple runs or within the same run?
--

Good question.

I mean in multiple runs.

Thanks.

Are you sure they're not running? This sounds more like a case of chef
doing what it's supposed to which is not changing something that
doesn't need to be changed. The recipes are likely being run but Chef
says "file hasn't changed. nothing to do" or "service is already
running. nothing to do".

There are some cases where recipes are coded to actually remove
themselves from the run list after one run but that's a rare case and
certainly not in any opscode official cookbook I've ever seen. I've
only used that sparingly.




Archive powered by MHonArc 2.6.16.

§