Windows食谱中的厨师NOT_IF和ONLY_IF验证问题 [英] Chef NOT_IF and ONLY_IF validation issue in Windows recipes

查看:59
本文介绍了Windows食谱中的厨师NOT_IF和ONLY_IF验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行此简单的配方块以在IIS中创建Web应用

Im runing this simple recipe block to create a web app in IIS

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部分始终为真

The problem here its that the NOT_IF part its allways 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

现在,我的问题是关于如何在其中返回True或False NOT_IF
取决于我的代码返回值??

Now, my question is about how to return True or False in the NOT_IF depending on my code return value ??

推荐答案

您应该利用Windows的powershell_out资源

You should take advantage of the powershell_out resource from the windows cookbook.

因此,如果输出为空,则可以检查命令的错误或其他错误。

With that you may check the error of a command or not ot if the output is empty.

在您的情况下,应该这样做:

In your case this should do:

only_if powershell_out("get-website | where-object { $_.name -eq  'My_Web_App' }").stdout.empty?

这篇关于Windows食谱中的厨师NOT_IF和ONLY_IF验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆