Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why in all OpsCode's cookbooks there is a

default[:netkernel][:version] = "4.1.1"
default[:netkernel][:install_url] = ""

default[:netkernel][:frontend][:port] = 8080

default[:netkernel][:backend][:address] = "localhost"
default[:netkernel][:backend][:port] = 1060

default[:netkernel][:user] = "netkernel"
default[:netkernel][:log_path] = "/var/log/netkernel"

instead of

default[:netkernel] = {
  :version => "4.1.1",
  :install_url => "",
  :frontend => {
    :port => 8080
  :backend => {
    :address => "localhost"
  :backend => {
    :port => 1060
  :user => "netkernel",
  :log_path => "/var/log/netkernel"

Is this attributes definition equal to the first one?

Why first variant is prefered?

share|improve this question

They are indeed quite different and there for a reason, Mike's answer doesn't take into account how Chef works ( no offence meant ).

When looking a node attributes, you have to take into account the fact that a node has a run_list which defines the order in which cookbooks are run. Before any of the recipes are run, chef will iterate through the run_list and bring in cookbooks, each time merging in that cookbook's attributes.

In addition, each of the run_list element's dependent cookbooks will also be rolled in ( worth nothing dependent cookbooks are evaluated before the "parent" ).

So let's say you had two cookbooks "base_netkernel" and "specific_case_netkernel", you could have valid defaults set in base_netkernel and then only provide the attributes that are different / specific in specific_case_netkernel.

Hopefully that makes sense ;) If not, there's always the docs :

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.