RE: Prevent resource from triggering multiple times in a single run

I think you want to use an only_if or not_if guard for this situation. If this really is a remote_file resource (rather than just an example), you may also want to look into the create_if_missing action instead of the create action; I don’t know if that solves your specific problem, though.

Kevin Keane

The NetTech

http://www.4nettech.com

Our values: Privacy, Liberty, Justice

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

-----Original message-----
From: Mark Selby mselby@unseelie.name
Sent: Saturday 29th August 2015 13:42
To: chef@lists.opscode.com
Subject: [chef] Prevent resource from triggering multiple times in a single run

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!

Thanks for the response. I use guards all the time but it will not solve
my issue here. The remote_file can change and when it does I need it to
be updated. The guard would actually prevent that.

This is also a more generalized question. Say for example I have 30
different recipes that may want to download the same file. I know that
as long at the 1st one works then I am good. I want to prevent the next
29 http head requests because in this case they are "expensive" and I
know that I do not need to do them in this run anymore.

This could apply to any resource.

On 8/29/15 2:05 PM, Kevin Keane Subscription wrote:

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

I think you want to use an only_if or not_if guard for this situation.
If this really is a remote_file resource (rather than just an
example), you may also want to look into the create_if_missing action
instead of the create action; I don't know if that solves your
specific problem, though.

Kevin Keane

The NetTech

http://www.4nettech.com

Our values: Privacy, Liberty, Justice

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

-----Original message-----
*From:* Mark Selby <mselby@unseelie.name>
*Sent:* Saturday 29th August 2015 13:42
*To:* chef@lists.opscode.com
*Subject:* [chef] Prevent resource from triggering multiple times
in a single run

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!

Would file.mtime test work. If the mtime is less than a few minutes then
would it be safe to assume that it was modified previously in the run?
On Sat, Aug 29, 2015 at 6:12 PM Mark Selby mselby@unseelie.name wrote:

Thanks for the response. I use guards all the time but it will not solve
my issue here. The remote_file can change and when it does I need it to be
updated. The guard would actually prevent that.

This is also a more generalized question. Say for example I have 30
different recipes that may want to download the same file. I know that as
long at the 1st one works then I am good. I want to prevent the next 29
http head requests because in this case they are "expensive" and I know
that I do not need to do them in this run anymore.

This could apply to any resource.

On 8/29/15 2:05 PM, Kevin Keane Subscription wrote:

I think you want to use an only_if or not_if guard for this situation. If
this really is a remote_file resource (rather than just an example), you
may also want to look into the create_if_missing action instead of the
create action; I don't know if that solves your specific problem, though.

Kevin Keane

The NetTech

http://www.4nettech.com

Our values: Privacy, Liberty, Justice

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

-----Original message-----
From: Mark Selby mselby@unseelie.name mselby@unseelie.name
Sent: Saturday 29th August 2015 13:42
To: chef@lists.opscode.com
Subject: [chef] Prevent resource from triggering multiple times in a
single run

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!

I would place that "could be called by multiple recipes" resource into its own recipe, and then "include_recipe" that recipe from all the recipes who depend on it. Chef should not add that resource to the resource collection more than once, so even though 30 recipes included that one shared recipe, Chef should only perform those actions one time.

Adam

On Aug 29, 2015, at 18:11, Mark Selby mselby@unseelie.name wrote:

Thanks for the response. I use guards all the time but it will not solve my issue here. The remote_file can change and when it does I need it to be updated. The guard would actually prevent that.

This is also a more generalized question. Say for example I have 30 different recipes that may want to download the same file. I know that as long at the 1st one works then I am good. I want to prevent the next 29 http head requests because in this case they are "expensive" and I know that I do not need to do them in this run anymore.

This could apply to any resource.

On 8/29/15 2:05 PM, Kevin Keane Subscription wrote:
I think you want to use an only_if or not_if guard for this situation. If this really is a remote_file resource (rather than just an example), you may also want to look into the create_if_missing action instead of the create action; I don't know if that solves your specific problem, though.

Kevin Keane

The NetTech

http://www.4nettech.com
Our values: Privacy, Liberty, Justice

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

-----Original message-----
From: Mark Selby mselby@unseelie.name
Sent: Saturday 29th August 2015 13:42
To: chef@lists.opscode.com
Subject: [chef] Prevent resource from triggering multiple times in a single run

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!