Chef配置对象

时间:2016-09-08 13:23:45

标签: ruby chef

我正在修改一些Chef Ruby代码,偶然发现了一个如下所示的部分:

if config[:role]
    nodes_to_process = [config[:role], ]
else
    nodes_to_process = rest.get('nodes').keys()
end

我已经打印出在该数组中找到的值,但无法理解为什么只根据在:role中找到的值执行该部分代码。

这是一个常量,是Chef或Knife类的一部分吗?

由于

1 个答案:

答案 0 :(得分:0)

我明白了。它与您在创建自定义刀插件时可以添加的选项相关。如果我有一个名为版本的选项,并且我已经配置了一些设置,那么我可以执行以下操作:

What my option may look like...
option :omg,
  :short => '-V',
  :long => '--version',
  :boolean => true,
  :description => "Print items with this version or lower."

Enter the following in your terminal...
$ knife my_custom_plugin --version 1.0

In your code...
def run
  if config[:version]
    # If the version flag was passed in
    puts "Version flag passed in."
  else
    # If the version flag was not passed in
    puts "Version flag not passed in."
  end
end

Custom Knife Plugin Reference