调用厨师独奏的惯用方式是什么?大多数网站都是这样做的:
chef-solo -c ~/solo.rb -j ~/node.json -r http://www.example.com/chef-solo.tar.gz
Run Code Online (Sandbox Code Playgroud)
但这很长。我可以想到一些更短的方法来做到这一点:
rake chef-solo
)。run-chef-solo
)。chef-solo
)。这样做的惯用方法是什么?其他厨师用户如何调用厨师?
默认情况下,chef-solo
从/etc/chef/solo.rb
. 命令行参数对应于可以在此文件中设置的配置值。这是使用 mixlib-config 库完成的。
option :config_file,
:short => "-c CONFIG",
:long => "--config CONFIG",
:default => "/etc/chef/solo.rb",
:description => "The configuration file to use"
option :json_attribs,
:short => "-j JSON_ATTRIBS",
:long => "--json-attributes JSON_ATTRIBS",
:description => "Load attributes from a JSON file or URL",
:proc => nil
option :recipe_url,
:short => "-r RECIPE_URL",
:long => "--recipe-url RECIPE_URL",
:description => "Pull down a remote gzipped tarball of recipes and untar it to the cookbook ca
che.",
:proc => nil
Run Code Online (Sandbox Code Playgroud)
'option' 是配置文件值。
实际的配置文件/etc/chef/solo.rb
如下所示:
file_cache_path "/tmp/chef-solo"
cookbook_path "/tmp/chef-solo/cookbooks"
role_path "/tmp/chef-solo/roles"
json_attribs "/tmp/chef-solo/node.json"
recipe_url "http://www.example.com/chef-solo.tar.gz"
Run Code Online (Sandbox Code Playgroud)
另请注意,JSON 文件也可以是远程 URL。
json_attribs "http://www.example.com/node.json"
Run Code Online (Sandbox Code Playgroud)
您也可以在配置文件中使用 Ohai 作为库,以检测平台或其他属性以指定要使用的 JSON 文件。
require 'rubygems'
require 'ohai'
o = Ohai::System.new
o.all_plugins
file_cache_path "/tmp/chef-solo"
cookbook_path "/tmp/chef-solo/cookbooks"
role_path "/tmp/chef-solo/roles"
json_attribs "/tmp/chef-solo/#{o[:platform]}.json"
recipe_url "http://www.example.com/chef-solo.tar.gz"
Run Code Online (Sandbox Code Playgroud)
然后,例如,您将拥有“平台”特定的 JSON 文件。或者,您可以使用o[:hostname]
,o[:domain]
或o[:fqdn]
基于主机名、域或 fqdn 使用 JSON 文件。但是,一旦您开始使用服务器脚手架来支持这种动态配置,您可能会考虑运行 Chef 服务器 :-)。