- From: Mike <
>
- To:
- Subject: [chef] Re: Chef solo setting default values
- Date: Wed, 29 Aug 2012 08:32:41 -0400
Hi Jan,
This is indeed an interesting question.
I've simulated this in shef, and here's the output:
http://pastebin.com/SYaGZptX
A few things come to mind.
test2 is an attribute, not a Hash, so accessing it is slightly
different than a hash, as in there is logic inside for things like
@has_been_read, @current_nesting_level.
These probably have to do with "deep merging" of attributes and such,
and calling node[:test2_value2]['name'] seems to create another
attribute, and step into that attribute.
Setting an attribute to a variable, instead of into another attribute
structure, may achieve what you're after. Maybe something like this:
chef:attributes > node[:test3] = {"foo" => "bar"}
=> {"foo"=>"bar"}
chef:attributes > node[:test3].class
=> Chef::Node::Attribute
chef:attributes > my_test_attribute = node[:test3]
=> #<Chef::Node::Attribute @current_automatic=nil, @default={...},
@set_unless_value_present=false, @current_override=nil,
@auto_vivifiy_on_read=false, @automatic={...}, @override={...},
@current_default=nil, @has_been_read=false,
@current_nesting_level=[:test3], @normal={...},
@current_normal={"foo"=>"bar"}, @set_type=nil>
chef:attributes > my_test_attribute.class
=> Chef::Node::Attribute
chef:attributes > my_test_attribute['foo']
=> "bar"
chef:attributes > my_test_attribute['foo']
=> "bar"
Hope this helps,
-Mike
On Wed, Aug 29, 2012 at 3:31 AM, Jan Bares
<
>
wrote:
>
Hi,
>
>
Can someone help me to understand this strange behaviour? As you can see
>
bellow, value of node[:test_value2]["name"] magically disappears after I
>
reference it for the first time. It should print:
>
[2012-08-29T09:25:43+02:00] INFO: [jan] value, value.
>
But it prints:
>
[2012-08-29T09:25:43+02:00] INFO: [jan] value, .
>
>
If this is known limitation of Chef, how can I reuse configuration data
>
without retyping them?
>
>
Thanks, Jan
>
>
attributes/default.rb
>
=====================
>
default[:test1] = "test"
>
default[:test_value1] = default[:test1]
>
>
default[:test2] = {"name" => "value"}
>
default[:test_value2] = default[:test2]
>
>
recipes/default.rb
>
==================
>
Chef::Log.info("[jan] #{node[:test_value1]}, #{node[:test_value1]}.")
>
Chef::Log.info("[jan] #{node[:test_value2]["name"]},
>
#{node[:test_value2]["name"]}.")
>
>
Output
>
======
>
[2012-08-29T09:25:42+02:00] INFO: *** Chef 10.12.0 ***
>
[2012-08-29T09:25:43+02:00] INFO: Setting the run_list to
>
["recipe[soa::default]
>
"] from JSON
>
[2012-08-29T09:25:43+02:00] INFO: Run List is [recipe[soa::default]]
>
[2012-08-29T09:25:43+02:00] INFO: Run List expands to [soa::default]
>
[2012-08-29T09:25:43+02:00] INFO: Starting Chef Run for prgsoa001
>
[2012-08-29T09:25:43+02:00] INFO: Running start handlers
>
[2012-08-29T09:25:43+02:00] INFO: Start handlers complete.
>
[2012-08-29T09:25:43+02:00] INFO: [jan] test, test.
>
[2012-08-29T09:25:43+02:00] INFO: [jan] value, .
>
[2012-08-29T09:25:43+02:00] INFO: Chef Run complete in 0.010143 seconds
>
[2012-08-29T09:25:43+02:00] INFO: Running report handlers
>
[2012-08-29T09:25:43+02:00] INFO: Report handlers complete
>
>
As you can see, the
>
>
Jan Bareš
>
Calypso Lead Developer
>
>
In association with
>
WOOD & Company Financial Services, a.s.
>
Palladium, Náměstí Republiky 1079/1a
>
110 00 Prague, Czech Republic
>
Tel. +420 222 096 111
>
Direct +420 222 096 378
>
Fax. +420 222 096 222
>
>
>
>
>
>
>
DISCLAIMER
>
WOOD & Company Financial Services, a.s. and its branches are authorized and
>
regulated by the CNB as Home State regulator and in Poland by the KNF, in
>
Romania by the CNVM, in Slovakia by the NBS and in the UK by the FSA as
>
Host State regulators. For further information about WOOD & Co., its
>
investment services, financial instruments and associated risks, safeguard
>
client assets (incl. compensation schemes) and contractual relationship
>
please see our website at www.wood.cz under section Corporate Governance.
>
>
Unless otherwise stated, this transmission is neither an offer nor the
>
solicitation of an offer to sell or purchase any investment. All estimates,
>
opinions and other information contained herein are subject to change
>
without notice and are provided in good faith but without legal
>
responsibility or liability. Opinion may be personal to the author and may
>
not reflect the opinions of WOOD & Co. Communications from sales persons,
>
sales traders or traders should not be regarded as investment research and
>
may contain opinions or trading ideas which are different from WOOD & Co.
>
investment research opinions.
>
>
This e-mail and any attachments are confidential and may be privileged or
>
otherwise protected from disclosure. If you are not a named addressee you
>
must not use, disclose, distribute, copy, print or rely on this e-mail and
>
any of its attachments. Please notify the sender that you have received
>
this email by mistake by replying to the email, and then delete the email
>
and any copies of it. Although WOOD & Co. routinely screens e-mails for
>
viruses, addressees should scan this e-mail and any attachments for
>
viruses. WOOD & Co. makes no representation or warranty as to the absence
>
of viruses in this e-mail or any attachments. Please note that to ensure
>
regulatory compliance and for the protection of our clients and business,
>
we may monitor and read e-mails sent to and from our server(s).
>
>
Archive powered by MHonArc 2.6.16.