Default attributes are merging


#1

Hi all,

I’ve tried to set up a bind DNS server using chef.

My bind cookbook has the following default attributes:
(cookbooks/bind/attributes/default.rb)
default[:bind][:upstream_servers] = [‘8.8.8.8’,‘8.8.4.4’] # e.g. the google DNS servers

However in my “production” environment file, I change them thus:
(environments/production.rb)
default_attributes({ “bind” => { “upstream_servers” => [ “xxx.xxx.xxx.xxx”, “yyy.yyy.yyy.yyy” ] })

When my template gets written however, I get all four values printed:
forwarders {
8.8.8.8;
8.8.4.4;
xxx.xxx.xxx.xxx;
yyy.yyy.yyy.yyy;
};

Have I misunderstood the way attributes get overwritten? I thought from this wiki page, the environment attributes OVERRIDE the cookbook attributes
http://wiki.opscode.com/display/chef/Attributes

I know I can obviously use override_attributes rather than default_attributes… but I didn’t expect this to happen anyway

Thanks!
Geoff


#2

If they are at the same precedence level, they get deep merged
together. Use precedence to override the value entirely.

Adam

On Tue, Oct 4, 2011 at 6:25 AM, Geoff Meakin Acid
geoffmeakin@aciddevelopments.co.uk wrote:

Hi all,

I’ve tried to set up a bind DNS server using chef.

My bind cookbook has the following default attributes:
(cookbooks/bind/attributes/default.rb)
default[:bind][:upstream_servers] = [‘8.8.8.8’,‘8.8.4.4’] # e.g. the google DNS servers

However in my “production” environment file, I change them thus:
(environments/production.rb)
default_attributes({ “bind” => { “upstream_servers” => [ “xxx.xxx.xxx.xxx”, “yyy.yyy.yyy.yyy” ] })

When my template gets written however, I get all four values printed:
forwarders {
8.8.8.8;
8.8.4.4;
xxx.xxx.xxx.xxx;
yyy.yyy.yyy.yyy;
};

Have I misunderstood the way attributes get overwritten? I thought from this wiki page, the environment attributes OVERRIDE the cookbook attributes
http://wiki.opscode.com/display/chef/Attributes

I know I can obviously use override_attributes rather than default_attributes… but I didn’t expect this to happen anyway

Thanks!
Geoff


Opscode, Inc.
Adam Jacob, Chief Product Officer
T: (206) 619-7151 E: adam@opscode.com


#3

Adam Jacob adam@opscode.com writes:

My bind cookbook has the following default attributes:
(cookbooks/bind/attributes/default.rb)
default[:bind][:upstream_servers] = [‘8.8.8.8’,‘8.8.4.4’] # e.g. the google DNS servers

However in my “production” environment file, I change them thus:
(environments/production.rb)
default_attributes({ “bind” => { “upstream_servers” => [ “xxx.xxx.xxx.xxx”, “yyy.yyy.yyy.yyy” ] })

When my template gets written however, I get all four values printed:
forwarders {
8.8.8.8;
8.8.4.4;
xxx.xxx.xxx.xxx;
yyy.yyy.yyy.yyy;
};

Have I misunderstood the way attributes get overwritten? I thought from this wiki page, the environment attributes OVERRIDE the cookbook attributes
http://wiki.opscode.com/display/chef/Attributes

I know I can obviously use override_attributes rather than default_attributes… but I didn’t expect this to happen anyway

If they are at the same precedence level, they get deep merged
together. Use precedence to override the value entirely.

hi,

Can you be more accurate please ?
Reading http://wiki.opscode.com/display/chef/Attributes it seems to me
there can’t be same precedence levels.

It says “default attributes applied in an environment” has
higher precedence than “default attributes applied in an attributes
file”

Also, can http://wiki.opscode.com/display/chef/Deep+Merge be more
accurate as well please ?
Here it doesn’t work at all as written on this page.
see https://gist.github.com/1376294


Laurent


#4

laurent+opscode@u-picardie.fr writes:

[…]

If they are at the same precedence level, they get deep merged
together. Use precedence to override the value entirely.

hi,

Can you be more accurate please ?
Reading http://wiki.opscode.com/display/chef/Attributes it seems to me
there can’t be same precedence levels.

It says “default attributes applied in an environment” has
higher precedence than “default attributes applied in an attributes
file”

Also, can http://wiki.opscode.com/display/chef/Deep+Merge be more
accurate as well please ?
Here it doesn’t work at all as written on this page.
see https://gist.github.com/1376294

Ok, i kind of answer to myself with the informations Matthew has put in
CHEF-2737.

for the first question, i have missed the important part in the
attribute documentation page =>
http://wiki.opscode.com/display/chef/Attributes#Attributes-SettingAttributesattheSamePrecedenceLevel :slight_smile: