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

In Chef 10 I have a number of roles which set custom node attributes like

"appname": "my_rails_app"

The attribute is then used to load app specific variables in a wrapper cookbook. There are different variables and number of variables for each Rails app for example.

app = Chef::EncryptedDataBagItem.load('deploy', node.appname)

In Chef 11 my run fails because 'node.appname' isn't set until after a successful Chef run. This means server creation has become a 2 step process - launch with base role then bootstrap wrapper cookbook.

I understand why this behavior was changed but I'm curious how to work around it without rewriting my cookbooks and still adhere to DRY.


Thanks this is interesting but I'm not sure this works. For example, the generic deploy cookbook which also depends on appname is included in the my_rails_app recipe. So a run looks like

Role - where attribute is set

"appname": "my_rails_app"

App wrapper cookbook - load variables

include_recipe "deploy"
app = Chef::EncryptedDataBagItem.load('deploy', node.appname)

Deploy cookbook - load SSH keys

app = Chef::EncryptedDataBagItem.load('deploy', node.appname)

The deploy cookbook is what kills the Chef run.

share|improve this question
up vote 2 down vote accepted

Default attributes already defined in a cookbooks attribute files can be resolved again during a chef client run with node.from_file:

# set the attribute
node.set[:appname] = "my_rails_app"

# optionally reload node so attribute is available during this chef-client run
node.from_file( run_context.resolve_attribute('your-railapp-cookbook', 'default') )

# and log it. "appname [#{node[:appname]}]" )

This is a section yanked from my answers about using attributes:

If you are doing this, you may need to think about saving the node back to the server if this is an important enough checkpoint in your process to warrant extra calls back to the chef server.

share|improve this answer
see UPDATE above. – upbeat.linux Sep 13 '13 at 5:48
So the same error is thrown when you use that code? You might need a default attribute defined in the cookbook you are reloading for chef to load the node override. default[:appname] = 'default' or whatever suits your code. I never got into the gory detail of what the reload does because it just worked for me, but I tend to define everything in the attribute files. – Matt Sep 13 '13 at 9:20

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.