我在Windows上与chef-client(12.18.31,嵌入式Ruby是ruby 2.3.1p112)遇到了一个奇怪的问题(bug)。在配方中使用节点属性的值是不够的 - 我需要将它与true
进行比较。具体来说:
desired_mcafee_state =
node['McAfee_enabled'] ? [:enable, :start] : [:disable, :stop]
puts "DEBUG: McAfee is #{node['McAfee_enabled']}, desired state is: #{desired_mcafee_state}"
这会产生调试输出:
DEBUG: McAfee is false, desired state is: [:enable, :start]
这个语法:
desired_mcafee_state =
node['McAfee_enabled'] == true ? [:enable, :start] : [:disable, :stop]
puts "DEBUG: McAfee is #{node['McAfee_enabled']}, desired state is: #{desired_mcafee_state}"
正确生成:
DEBUG: McAfee is false, desired state is: [:disable, :stop]
这在irb中运行良好:
$ irb
irb(main):001:0> node={}
=> {}
irb(main):002:0> node['McAfee_enabled']=false
=> false
irb(main):003:0> desired_mcafee_state =
irb(main):004:0* node['McAfee_enabled'] ? [:enable, :start] :
[:disable, :stop]
=> [:disable, :stop]
我不明白的错误或厨师的怪异?
答案 0 :(得分:1)
在评论中解释,值是字符串"false"
,这在Ruby的世界观中是真实的。