我正在运行这个简单的配方块来在 IIS 中创建一个 Web 应用程序
powershell_script "create_site_my_site" do
code "New-webapppool -name 'My_Web_App'; New-Website -Name 'My_Web_App' -applicationpool 'My_Web_App' -Port '80' -IPAddress * -PhysicalPath 'c:\webs\My_Web_App' "
action :run
not_if "get-website | where-object { $_.name -eq 'My_Web_App' }"
end
这里的问题是 NOT_IF 部分总是 True
PS C:\Users\carlos>
PS C:\Users\carlos> get-website | where-object { $_.name -eq 'asdfasdfasdf' }
PS C:\Users\carlos> echo $lastexitcode
1
PS C:\Users\carlos> get-website | where-object { $_.name -eq 'My_Web_App' }
Name ID State Physical Path Bindings
---- -- ----- ------------- --------
My_Web_App 6 Stopped c:\webs\My_Web_App http *:80:
https *:443:
PS C:\Users\carlos.camacho> echo $lastexitcode
1
现在,我的问题是如何在 NOT_IF 中返回 True 或 False
取决于我的代码返回值?
powershell_script "create_site_my_site" do
guard_interpreter :powershell_script
code "New-webapppool -name 'My_Web_App'; New-Website -Name 'My_Web_App' -applicationpool 'My_Web_App' -Port '80' -IPAddress * -PhysicalPath 'c:\webs\My_Web_App' "
action :run
not_if "get-website | where-object { $_.name -eq 'My_Web_App' }"
end
您需要指定guard_interpreter :powershell_script
。意识到CHEF-1943 https://github.com/opscode/chef/issues/1943并确保guard_interpreter位于守卫之前,并且不要将守卫放在块中。
powershell_script 文档 http://docs.getchef.com/resource_powershell_script.html#attributes
关于 Chef powershell 提供程序的一个很好的参考是这个视频 https://www.youtube.com/watch?v=BNV2jZUjKlc.
只需使用IIS 食谱 http://docs.getchef.com/opscode_cookbooks_iis.html是另一种选择。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)