4

I have several recipes in my cubrid cookbook which I use to install CUBRID Database on a Vagrant box. Each recipe has its own attributes file. Eg:

# attributes/default.rb for recipe/default.rb
default['cubrid']['home'] = "/opt/cubrid"

Then:

# attributes/demodb.rb for recipe/demodb.rb
set['cubrid']['demodb_dir'] = "#{node['cubrid']['home']}/databases/demodb"

Then in my recipe/demodb.rb I refer to its attributes like:

include_recipe "cubrid"

CUBRID_DEMODB_DIR = "#{node['cubrid']['demodb_dir']}"

# create a "demodb" directory if it doesn't exist
directory "#{CUBRID_DEMODB_DIR}" do
  user "vagrant"
  action :create
  not_if "test -d #{CUBRID_DEMODB_DIR}"
end

The above should create /opt/cubrid/databases/demodb directory. But it fails, because it tries to create /databases/demodb directory, meaning #{node['cubrid']['home']} was not set.

How do I correctly reference the attributes set in the parent attributes file?

esengineer
  • 9,514
  • 7
  • 45
  • 69

1 Answers1

4

Check out Chef Wiki => Cookbook Attribute File Ordering

Use

include_attribute 'cubrid'

in your attributes/demodb.rb

Draco Ater
  • 20,820
  • 8
  • 62
  • 86