Search code examples
chef-infrachef-recipechef-solo

wrapper cookbook adding attribute to resource


I am trying to change the default behavior of the IIS cookbook that uses the windows_feature resource to install the features. It is within a loop like below:

node['iis']['components'].each do |feature|
  windows_feature feature do
    action :install
  end
end

I am trying to get the wrapper cookbook to add an attribute to this resource. Such as:

w = resource(:windows_feature => "feature")
w.source "path_to_source_files"

Of course this is not working because "feature" is not defined. How do I accomplish this?


Solution

  • I figured out the answer to my question. It seems that if the cookbook doesn't allow for the flexibility to adjust specific attributes of a resource (i.e. the attributes weren't used/defined), then you simply depend on the cookbook to access its available attributes, but exclude 'include_recipe'.

    Original wrapper cookbook:

    metadata.rb

    depends 'iis'
    

    default.rb

    include_recipe 'iis::default'
    
    w = resource(:windows_feature => 'feature')
    w.source 'path_to_source_files'
    

    Fixed wrapper cookbook:

    metadata.rb

    depends 'iis'
    

    default.rb

    node['iis']['components'].each do |feature|
     windows_feature feature do
      action :install
      source 'path_to_source_files'
     end
    end