我正在运行这个简单的配方 block 以在 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并确保 guard_interpreter 在守卫之前,不要把守卫放在一个街区里。
powershell_script documentation
关于 Chef powershell 提供程序的一个很好的引用是 this video .
只需使用 IIS cookbook是另一种选择。
关于ruby - Windows Recipe 中的 Chef NOT_IF 和 ONLY_IF 验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25406353/