[chef] Re: Re: Could the resource guard documentation be clarified?


Chronological Thread 
  • From: Joe Nuspl < >
  • To:
  • Subject: [chef] Re: Re: Could the resource guard documentation be clarified?
  • Date: Wed, 4 Mar 2015 13:00:41 -0800

Yes, I found a subtle typo in the shellout stub the spec test was using.

Sorry about the fuss.

Joe

On Mar 4, 2015, at 12:29 PM, Daniel DeLeo < "> > wrote:



On Wednesday, March 4, 2015 at 10:27 AM, Joe Nuspl wrote:

I recently helped a colleague through some confusion about how multiple guards worked.

Greatly simplifying the code, the recipe looked like:

file '/foo/bar' do
only_if { true }
only_if { false }
end



The chef code treats these as OR while they thought it was AND.

We remedied the situation be changing it to:

file '/foo/bar' do
only_if do
true && false
end
end


Do you have a typo or something? If I run this:

file '/tmp/one' do
 only_if { true }
  only_if { false }
end

file '/tmp/two' do
 only_if { true && false }
end



Then both are skipped:

$ chef-apply repro.rb

Recipe: (chef-apply cookbook)::(chef-apply recipe)
* file[/tmp/one] action create (skipped due to only_if)
* file[/tmp/two] action create (skipped due to only_if)



While this case was straight forward, there is another case where chef-rewind is being used to add an additional clause. This will be more challenging.

So...

Is OR the correct behavior? Or should it be AND? Or do people not use multiple guards?
Each guard is a precondition that must be met for the resource’s action to be applied, and all preconditions must be met.   

Could https://docs.chef.io/chef/resources.html#guards be clarified?

Thanks.

Joe  
--  
Daniel DeLeo




Archive powered by MHonArc 2.6.16.

§