【问题标题】:Chef - print log at the end of statement if source isn't validChef - 如果源无效,则在语句末尾打印日志
【发布时间】:2016-04-19 02:08:32
【问题描述】:

这是我的代码:

if node['app']['source']
    src = "#{node['app']['source']}\\#{node['app']['file_name']}"
else 
    src = "second_source"
end

我想在我的语句末尾添加一个 log.warn,以防任何来源无效, 类似:

if node['app']['source']
    src = "#{node['app']['source']}\\#{node['app']['file_name']}"
else 
    src = "second_source"
whatever
    Chef::Log.warn "This path #{src} is not supported, check attributes again"
    return
end

如果有人有任何想法,我会很高兴, 谢谢...

【问题讨论】:

标签: ruby chef-infra cookbook recipe


【解决方案1】:

代码不是这样工作的,条件可以为真或假,if/else 的两个分支涵盖了这两种情况。您必须想出一种方法来检查来源是否有效并使用 if/elsif/else 或类似名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    相关资源
    最近更新 更多