Search code examples
chef-infrachef-recipe

Override Attributes with Wrapper cookbook


I just started to use Chef and want to install Hadoop on my node. So far I've got this very easy recipe which is not working.

my-hadoop/attributes/default.rb:

    default['hadoop']['core_site']['fs.defaultFS'] = "Test"


my-hadoop/recipes/default.rb:

    include_recipe "hadoop"

hadoop_cookbook/attributes/default.rb:

    default['hadoop']['core_site']['fs.defaultFS'] = "hdfs://#{node['fqdn']}"

This was my understanding of wrapper cookbooks after reading some blog posts. It is installing Hadoop but the default value is being used every time. Changing default to any other priority like 'override' doesn't solve the issue.

EDIT: The node's runlist is only 'recipe[slave]':

slave/recipes/default:

    include_recipe "my-hadoop"

Solution

  • Chef 11 requires dependencies to be set in your metadata.rb file. include_recipe really only includes the recipe file so the Chef run needs some hints as to what order to load the required cookbooks in.

    Your slave cookbook will depend on my-hadoop. Then my-hadoop will depend on hadoop_cookbook

    File slave/metadata.rb:
    depends "my-hadoop", "~> 1.5"
    
    File my-hadoop/metadata.rb:
    depends "hadoop_cookbook", "~> 1.3"
    

    If you had set the default attribute in the slave cookbook, I believe it would have just worked.