我正在构建一个对节点属性有要求的食谱。如果节点属性不存在,我想退出客户端运行并返回适当的错误。当顶级属性不存在时,我试图退出,即:
# Check for valid keepalived configuration on node
if node.default['keepalived'] = ""
Chef::Application.fatal!("No keepalived configuration was set on the node. Please add some.")
end
如果node ['keepalived']是一个数组(应该是这样),则会失败。如果它是空的(不存在)则通过。
如果尚未设置node ['keepalived'],我应该使用哪个语句退出,但如果有子值则继续?
答案 0 :(得分:2)
有两个问题,一个是=
vs ==
。其次,你要检查的是:
if !node['keepalived'] || node['keepalived'].empty?