- From: Xabier de Zuazo <
>
- To:
- Subject: [chef] Re: Wrapper Cookbook Attribute Overwrite Question
- Date: Fri, 13 Jun 2014 01:39:48 +0200
- Organization: Onddo Labs SL
On Thu, 12 Jun 2014 11:15:02 -0500
"David A. Williams"
<
>
wrote:
>
I'm setting up a wrapper cookbook to overwrite some node attributes.
>
However it appears when that attribute is a hash it runs both
>
configs. Has anyone experienced this?
>
>
For example in my base cookbook, I have
>
attributes/default.rb
>
default['operations']['tomcat_instances'] = {:Dev => { :port =>
>
'80', :sites => %w[Dev] }}
>
>
And in my wrapper cookbook, I have
>
recipes/raven_server.rb
>
node.set['operations']['tomcat_instances'] = {:QA=> { :port =>
>
'80', :sites => %w[Master Staging] }}
>
>
After the chef run. I have two Tomcat instances set up instead of
>
just one.
That's because you are setting different attribute types (default vs.
normal,set). In this case the Hashes are merged instead of replaced.
You should use same attribute type like for example:
node.default['operations']['tomcat_instances'] = {
:Dev => { :port => '80', :sites => %w[Dev] }
}
# ...
node.default['operations']['tomcat_instances'] = {
:QA=> { :port => '80', :sites => %w[Master Staging] }
}
Or reset default attribute type:
node.default['operations']['tomcat_instances'] = {
:Dev => { :port => '80', :sites => %w[Dev] }
}
# ...
node.default['operations']['tomcat_instances'] = {}
node.set['operations']['tomcat_instances'] = {
:QA=> { :port => '80', :sites => %w[Master Staging] }
}
I know this can be confusing, but keep in mind that the attributes are
of type Hash internally (Mash). These two things have the same effect:
node.set['operations']['tomcat_instances'] = {
:QA=> { :port => '80', :sites => %w[Master Staging] }
}
node.set['operations']['tomcat_instances']['QA']['port'] = '80'
node.set['operations']['tomcat_instances']['QA']['sites'] = %w[
Master
Staging
]
--
Xabier de Zuazo Oteiza
IT System Administrator - Onddo Labs S.L.
www.onddo.com
--------------------------------------------------------------------
Public Key =
http://www.onddo.com/xabier_zuazo.pub
Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468
--------------------------------------------------------------------
Attachment:
signature.asc
Description: PGP signature
Archive powered by MHonArc 2.6.16.