- From: Daniel DeLeo <
>
- To:
- Subject: [chef] Re: Re: Re: Re: How do I test an attribute value in an
- Date: Fri, 24 Jun 2011 08:29:16 -0700
On Friday, June 24, 2011 at 7:55 AM, ItsMikeE wrote:
>
How do I specify an only_if such that
>
>
only_if value of [:recipename][:recipeoption] is true
>
or
>
only_if value of [:recipename][:recipeoption] == value
>
>
I keep getting TypeError: Symbol as array index
>
What does that mean?
Two things here. First is a convention with not_if and only_if. When you pass
a code block to them, they execute the code and look at the result. Here are
some simple cases:
only_if { true } # Always
not_if { false } # always
only_if { false } # never
When you pass anything else, Chef tries to convert it to a string, and run it
as a command. These will have the same results as above:
only_if "/bin/true" # Always
not_if "/bin/false" # Always
only_if "/bin/false" # never
Second, in the code you posted, you're creating an Array
[:recipename]
With this array you can access the element by its position in the array:
[:recipename][0] #=> :recipename
but it makes no sense to use something other than an integer to access an
element in the array.
If you're trying to use attributes you set in the attributes file, these are
accessible via the `node` object in your recipes, so you probably wanted:
only_if { node[:some_value] }
HTH,
--
Dan DeLeo
Archive powered by MHonArc 2.6.16.