【问题标题】:chef not_if inside a only_if厨师 not_if 在 only_if 内
【发布时间】:2018-10-07 08:59:55
【问题描述】:

我可以在 only_if 块内有一个 not_if,比如

 only_if{ A == "A" && not_if { ::File.exists(/a.txt)}}

我的问题是这样的结构会起作用吗?还是我需要用不同的方式来做。

【问题讨论】:

    标签: chef-infra chef-recipe


    【解决方案1】:

    您需要以不同的方式进行操作。 only_if{ A == "A" && !::File.exists(/a.txt) } 或类似的。

    【讨论】:

    • 这些答案中的任何一个都有效。如果您没有看到您想要的行为,则可能有其他问题。
    【解决方案2】:

    没有真正的代码很难说,但你试过这种结构吗?

    only_if { A == "A" }  
    not_if { ::File.exists(/a.txt) }
    

    【讨论】:

    • 是的,上面的结构由于某种原因没有运行 not_if 块。
    • 它只运行not_if是第一个后卫传球。
    • 没错,如果only_if 最终为假,它将不会运行not_if...这是concept of condtional short circuiting,这绝对是您希望它的工作方式
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多