引用厨师独奏的地道方式?

引用厨师独奏的惯用方法是什么? 大多数网站都这样做:

chef-solo -c ~/solo.rb -j ~/node.json -r http://www.example.com/chef-solo.tar.gz 

但是这很长。 有几个简单的方法可以做到这一点,我可以想到:

  1. 一个耙子任务( rake chef-solo )。
  2. 一个小的shell脚本( run-chef-solo )。
  3. 一个别名(可以覆盖名称,像chef-solo )。

什么是这样做的惯用方法? 其他厨师用户如何调用厨师?

默认情况下, chef-solo/etc/chef/solo.rb读取configuration。 命令行参数对应于可以在此文件中设置的configuration值。 这是使用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 

“选项”是configuration文件的值。

实际的configuration文件/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" 

另外请注意,JSON文件也可以是远程URL。

 json_attribs "http://www.example.com/node.json" 

您也可以在configuration文件中使用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" 

然后你会有“平台”特定的JSON文件,例如。 或者您可以使用o[:hostname]o[:domain]o[:fqdn]来使用基于主机名,域或fqdn的JSON文件。 但是,一旦你开始让服务器的脚手架支持这种dynamicconfiguration,你可以看看运行一个厨师服务器:-)。

@ jtimberman已经写了一个很好的答案。 这是我个人调用厨师独奏的方式。 这使得基本的工作,你可能需要添加更多的属性/etc/chef/node.json并探讨其他答案中描述的一些选项。

 # cat > /etc/chef/solo.rb << EOF cookbook_path "/var/chef-solo/cookbooks" json_attribs "/etc/chef/node.json" EOF # cat > /etc/chef/node.json << EOF { "run_list": ["recipe[foo]", "recipe[bar]"] } EOF 

您可以将您的食谱复制到/var/chef-solo/cookbooksrecipe_url web服务器上并使用recipe_url参数。 在节点上运行chef-solo是调用它所需要的。

如果可能的话,我试着把所有东西放在solo.rb因为我非常喜欢能够运行厨师独奏,而不必记住任何额外的参数。

请注意,chef-solo现在已被弃用,转而使用chef-client -z local-mode:

https://github.com/chef/chef-rfc/blob/master/rfc031-replace-solo-with-local-mode.md