2013-08-30 39 views
0

我的食譜使用IIS菜譜刪除再加入並啓動IIS網站,http綁定,然後使用shell_out命令,如下所示添加https綁定:廚師shell_out過早呼叫

iis_site iis_site_name do 
    action :delete 
end 


    ... other things ... 

iis_site iis_site_name do 
    protocol :http 
    port 80 
    path site_dir 
    application_pool iis_site_name 
    host_header site_header 
    action [:add,:start] 
end 

if https 
    https_binding(iis_site_name, site_header) 
end 


def https_binding(site_name, site_header) 
    cmd = "#{appcmd} set site /site.name:\"#{site_name}\" /+bindings.[protocol='https',bindingInformation='*:443:#{site_header}']" 
    Chef::Log.info("Running HTTPS config command") 
    Chef::Log.debug(cmd) 
    shell_out!(cmd, {:returns => [0,42]}) 
    Chef::Log.info("HTTPS config command run") 
end 

望着調試日誌,它表明https_binding日誌調試/信息調用之前IIS站點叫被刪除:

[2013-08-30T16:22:01+00:00] INFO: Running HTTPS config command 
[2013-08-30T16:22:01+00:00] DEBUG: C:\Windows\System32\inetsrv\appcmd.exe set site /site.name:"mysite" /+bindings.[protocol='https',bindingInformation='*:443:mysite.com'] 
ERROR (message:New binding object missing required attributes. Cannot add duplicate collection entry of type 'binding' 
with combined key attributes 'protocol, bindingInformation' respectively set to 'https, *:443:mysite.com' 
.) 
[2013-08-30T16:22:01+00:00] INFO: HTTPS config command run 
(up to date) 
Recipe: <Dynamically Defined Resource> 
* iis_site[mysite action delete[2013-08-30T16:22:01+00:00] INFO: Processing iis_site[mysite] action delete (c:/chef/cache/cookbooks/mycookbook/providers/website.rb line 47) 

爲什麼正在運行這些命令,這麼晚了,而不是他們是所謂的什麼時候?

回答

0

將我的代碼更改爲以下似乎工作,但我不喜歡這種方法。有沒有更好的辦法?

deleteSite = iis_site iis_site_name do 
end 

deleteSite.run_action(:delete) 


    ... other things ... 

createSite = iis_site iis_site_name do 
    protocol :http 
    port 80 
    path site_dir 
    application_pool iis_site_name 
    host_header site_header 
end 

createSite.run_action(:add) 
createSite.run_action(:start) 

if https 
    https_binding(iis_site_name, site_header) 
end 


def https_binding(site_name, site_header) 
    cmd = "#{appcmd} set site /site.name:\"#{site_name}\" /+bindings.[protocol='https',bindingInformation='*:443:#{site_header}']" 
    Chef::Log.info("Running HTTPS config command") 
    Chef::Log.debug(cmd) 
    shell_out!(cmd, {:returns => [0,42]}) 
    Chef::Log.info("HTTPS config command run") 
end