[chef] Re: Re: Re: Prevent resource from triggering multiple times in a single run


Chronological Thread 
  • From: Tensibai < >
  • To:
  • Subject: [chef] Re: Re: Re: Prevent resource from triggering multiple times in a single run
  • Date: Mon, 31 Aug 2015 10:01:39 +0200

According to your description, and if you wish to keep each cookbook independent you can do this to define the resource only if it does not exist already in the collection (you have to update all recipes defining this resource):

 

begin 

  r = resources("remote_file[/var/tmp/somefile")

rescue

  remote_file "/var/tmp/somefile" do
    source "http://binfiles/somefile"
    owner "root"
    group "root"
    mode "0644"
    action :create
  end

end

Le 2015-08-31 03:43, Mark Selby a écrit :

Thanks for response. I fully see the utility of the include_recipe paradigm.

Out of real curiosity you mentioned this -- "use a definition to edit the resource collection and the definition can check and exit if the resource always exists"

Would you happen to have any example code that might show how that works.

Thanks!



On 8/30/15 6:24 PM, Lamont Granquist wrote:

If its really a remote_file resource then those support etags and last-modified-since so it won't be expensive to run multiple times.

Generally when you have a call-many-times-run-only-once pattern you're looking at include_recipe'ing the expensive thing so it only gets created once in the resource collection.

You can also use a definition to edit the resource collection and the definition can check and exit if the resource always exists.

On 08/29/2015 01:42 PM, Mark Selby wrote:
remote_file "/var/tmp/somefile" do
    source "http://binfiles/somefile"
    owner "root"
    group "root"
    mode "0644"
    action :create
end

Lets just suppose that this is a somewhat expensive operation that may need to get called multiple times during a converge depending on what recipes the node is running. I would like to say "do not execute this resource if it has already been triggered during this run"

I would also not like to use a marker file if I can avoid it.

I know we have delayed execution but that is not what I want. I need this to trigger on the first call and then not again. Can I use the run_status or run_context to accomplish this?

Thanks!

 

 



Archive powered by MHonArc 2.6.16.

§