By default, chef-solo
reads its configuration from /etc/chef/solo.rb
. The command-line parameters correspond to config values that can be set in this file. This is done using the mixlib-config library.
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
The 'option' is the config file value.
The actual config file, /etc/chef/solo.rb
would look like:
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"
Also note that the JSON file can be a remote URL, too.
json_attribs "http://www.example.com/node.json"
You can use Ohai as a library within the config file as well, to detect the platform or other attributes to specify what JSON file to use.
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"
And then you'd have "platform" specific JSON files, for example. Or you could use o[:hostname]
, o[:domain]
or o[:fqdn]
to use JSON files based on the hostname, domain or fqdn. But once you start having the scaffolding of servers to support this kind of dynamic configuration, you might look at running a Chef Server :-).
In Chef, the node is the authority. The best practice is to use knife bootstrap to get a system set up to run chef and integrate it with the Chef server.
The majority of the node attribute data is generated dynamically by the node when chef-client runs, where it uses ohai to discover information about itself. Other data can come from cookbooks and roles. Your cookbooks and roles should certainly be stored in your version control repository, in what is typically called the Chef Repository.
The main reason to store nodes locally is to capture their run lists. We recommend that you have a runbook document in your repository (like a README :)) that describes what kinds of servers you have and what their roles are.
Best Answer
Yes, you can use the
-j
json file option to populate node attributes.This will make an attribute named
my_attribute
available in your cookbooks. For example,Or,
Setting an initial run_list is the most common use of the json attributes file for Chef Client. If you're using Chef Client + Chef Server, though, you can simply modify the node object on the server either through the webui (Open Source Chef Server) or management console (Opscode Hosted/Private Chef), or through
knife node edit
if you're using the command-line tool, knife.Note that using the JSON file is like modifying the node object on the server, the attributes set here "normal" priority like when they are used in a recipe, and these attribute values will be saved to the Node object on the server at the end of a successful run.