The problem is that the function is defined inside the recipe and can only be used in this recipe. The include_recipe method ensures that the recipe is loaded, but it does not import anything into the recipe that makes the inclusion.
Since your function is used to declare a chef's resource with some calculated parameters, the closest thing you can pay attention to is Definition (Chef Docs) . Definitions look similar to resources that have a name and a set of optional parameters, but are actually simple macros that expand into a recipe when compiled.
In your cookbook directory, create definitions/my_iis_website.rb containing something like:
define :my_iis_website do iis_site websiteName do protocol :http port 80 path "#{node['iis']['docroot']}/#{websiteName}" host_header "#{websiteName}.test.kermit.a-aws.co.uk" action [:add,:start] end end
Then replace the loop in your recipe with:
for websiteName in websiteNames do my_iis_website websiteName end
If your recipes for each server cluster are identical, but for a list of sites, you may want to save this data in attributes or data bags . This will help you avoid repeating yourself in your recipes, and also allow you to add sites without updating your cookbook.
source share