下面是一个工作配方示例,它循环遍历一系列网站名称,并使用createIisWebsite()函数在IIS中创建它们.
def createIisWebsite(websiteName)
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
Run Code Online (Sandbox Code Playgroud)
在我们的实际解决方案中,此数据存储在其他位置并通过Web API访问.
websiteNames = ["website-2", "website-3", "website-4"]
for websiteName in websiteNames do
createIisWebsite websiteName
end
Run Code Online (Sandbox Code Playgroud)
现在我希望能够从本Cookbook中的多个配方中调用createIisWebsite()函数.
我试过把它扔进一个帮助模块(库).在那里,我无法获得对iis_site的引用.
我已经尝试将函数移动到default.rb然后执行include_recipe":: default".这似乎也不起作用.
我得到一个"在Windows版本6.2.9200上找不到createIisWebsite的资源"
我采用这种方法的原因是因为我希望有一个包含每个Web服务器集群的网站列表的配方.我觉得我没有采取最好的练习路线.
有任何想法吗?