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"

run_list(%w{
  recipe[tomcat::default]
})

default_attributes(
  :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.

Thanks

link|improve this question

75% accept rate
feedback

1 Answer

up vote 2 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:

"#{node[:tomcat][:java_options]}#{node[:tomcat][:log_dir]}"
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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