cca*_*cho 2 ruby powershell chef-infra chef-recipe
我运行这个简单的食谱块在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
Run Code Online (Sandbox Code Playgroud)
这里的问题是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
Run Code Online (Sandbox Code Playgroud)
现在,我的问题是如何根据我的代码返回值在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
Run Code Online (Sandbox Code Playgroud)
你需要指定guard_interpreter :powershell_script.注意CHEF-1943并确保guard_interpreter在防守之前并且不要将防护装置放在一个区块内.
这个视频是关于Chef powershell提供商的一个很好的参考.
只需使用IIS cookbook就是另一种选择.