下面是一個工作配方示例,它循環訪問一系列網站名稱,並使用函數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
在我們的實際解決方案中,這些數據存儲在別處並通過web API訪問。
websiteNames = ["website-2", "website-3", "website-4"]
for websiteName in websiteNames do
createIisWebsite websiteName
end
現在我希望能夠從本食譜中的多個食譜調用函數createIisWebsite()。
我已經嘗試將它投入輔助模塊(庫)。在那裏,我無法獲得iis_site的參考。
我試着將函數移動到default.rb
,然後做include_recipe「:: default」。這似乎也不起作用。
我得到一個「無法找到createIisWebsite資源上的Windows版本6.2.9200」
我採取這種做法的原因是因爲我想有一個包含每個Web服務器集羣網站列表中的配方。我感覺我沒有采取最佳的練習路線。
任何想法?
Ohai!你有沒有找到解決這個問題的辦法?任何答案都有幫助嗎?請不要忘記將其中一個標記爲正確:) – sethvargo 2014-02-01 18:34:21