- From: Nathaniel Eliot <
>
- To:
- Cc: Daniil S <
>
- Subject: [chef] Re: Re: node.attribute? check nested
- Date: Sun, 14 Jul 2013 11:47:43 -0500
Good practice here to make sure you're setting default['foo'] = {} in
your attributes file. Otherwise, a "tried to treat a nil like a hash"
error will break your script, if node['foo'] isn't set.
If you can't be sure that node['foo'] will be set (for some reason),
you can append a 'rescue false' to your test, to prevent that:
if ( (!node['foo']['bar'].nil?) rescue false)
# do something only if node['foo']['bar'] is set
end
(Note that the rescue modifier will eat *all* errors within the clause
it modifies. Don't use it for more complicated statements.)
Cheers,
--
Nathaniel Eliot
T9 Productions
On Sun, Jul 14, 2013 at 11:24 AM, Nic Grayson
<
>
wrote:
>
node['foo']['bar'] is just a variable so any ruby logic will work
>
>
puts "it's not set" unless node['foo']['bar']
>
>
if node['foo']['bar'] == "biz" etc.
>
>
>
On Sun, Jul 14, 2013 at 11:02 AM, Daniil S
>
<
>
>
wrote:
>
>
>
> Hello.
>
> Official documentation mentions such construction:
>
> not_if { node.attribute?("some_command_complete") }
>
>
>
> Can I check nested attribute with it?
>
> For example, if i have attribute node['foo']['bar'], how can i check if it
>
> is set?
>
>
Archive powered by MHonArc 2.6.16.