[chef] Re: Optional resource additions at converge-time?


Chronological Thread 
  • From: Jay Feldblum < >
  • To:
  • Subject: [chef] Re: Optional resource additions at converge-time?
  • Date: Mon, 30 Jul 2012 17:08:02 -0400

KC,

Try passing the condition as a block:

package "foo" do
  only_if { condition }
end

Cheers,
Jay

On Mon, Jul 30, 2012 at 4:28 PM, KC Braunschweig < " target="_blank"> > wrote:
I'm wondering if there is a better way to accomplish this. I have a
situation where I want to declare a resource optionally based on some
attributes and other factors. Simple enough right?

if criteria
  package foo
end

or even

package foo do
  only_if criteria
end

However the ruby if, and the only_if too it seems, are processed at
compile time so it will effectively ignore an attribute that is
set/changed in another cookbook/recipe that falls later in the
runlist. This is a common case if you have "base" cookbooks that
provide a bunch of settings with defaults that can be toggled as
needed by other more specific cookbooks. We worked around this by
using a ruby block to process the criteria and then optionally define
resources and shove them into run_contenxt.resource_collection but
it'd be great if there was a cleaner way. Are only_if/not_if meant to
apply at compile time? Is there / should there be a way to change
this? This also comes up with templates because the variables param
seems to be processed at compile time so if you pass in attributes
that may change during compilation of later recipes you can hit a
similar problem.

KC




Archive powered by MHonArc 2.6.16.

§