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

I'm able to set attributes in role files as documented but I'm not able to access attributes already set by cookbooks that I'm using.

For example within /roles/appserver.rb:

name "appserver"


  :tomcat => {
    :java_options => "-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=" + node[:tomcat][:log_dir]

What I get is an exception stating chef can't find the 'node' method/variable.


share|improve this question
up vote 11 down vote accepted

You cannot. The role Ruby DSL is converted from Ruby to JSON when you upload the role to the server with knife. The node object is not available, since it is not processed in the context of a Chef run.

If you want to combine node attributes, instead, you should do that in a recipe, for example:

share|improve this answer

You can actualy use require_relative 'base_role_file' inside a role and this required file may set some global variables for you to use. Pretty hacky.

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.