Chef - Solo Setup


Advertisements

Chef-Solo is an open source tool that runs locally and allows to provision guest machines using Chef cookbooks without the complication of any Chef client and server configuration. It helps to execute cookbooks on a self-created server.

Before running Chef-Solo on the local machine, one needs to install the following two files on the local machine.

  • Solo.rb − This file tells Chef about where to find cookbooks, roles, and data bags.

  • Node.json − This file sets the run list and any node-specific attribute, if required.

solo.rb Configuration

Following are the steps to configure solo.rb.

Step 1 − Create a solo.rb file inside the chef repo.

current_dir       = File.expand_path(File.dirname(__FILE__)) 
file_cache_path   "#{current_dir}" 
cookbook_path     "#{current_dir}/cookbooks" 
role_path         "#{current_dir}/roles" 
data_bag_path     "#{current_dir}/data_bags" 

Step 2 − Add the file to git repo.

$ git add solo.rb 

Step 3 − Create a node.json file inside the chef repo with the following content.

{ 
   "run_list": [ "recipe[ntp]" ] 
} 

Step 4 − Get the ntp cookbook inside the chef repo using knife.

vipin@laptop:~/chef-repo $ knife cookbook site install ntp 
Installing ntp to /Users/mma/work/chef-repo/cookbooks 
…TRUNCATED OUTPUT… 
Cookbook ntp version 1.3.0 successfully installed 

Step 5 − Add the node.json file to Git.

$ git add node.json 

Step 6 − Commit and push the files to git repo.

vipin@laptop:~/chef-repo $ git commit -m "initial setup for Chef Solo" 
vipin@laptop:~/chef-repo $ git push 
Counting objects: 4, done. 
Delta compression using up to 4 threads. 
...TRUNCATED OUTPUT... 
To git@github.com:mmarschall/chef-repo.git 
b930647..5bcfab6 master -> master 

Running the Cookbook on the Node

Step 1 − Login to the node where one wants to provision the Chef-Solo.

Step 2 − Clone the Chef repo on the machine.

$ git clone $URL_PATH 

Step 3 − cd to the chef repo.

$ cd chef-repo 

Finally, run the Chef-Solo to converge the node −

$ sudo chef-solo -c solo.rb -j node.json 
[2017-20-08T22:54:13+01:00] INFO: *** Chef 11.0.0 *** 
[2017-20-08T22:54:13+01:00] INFO: Setting the run_list to 
["recipe[ntp]"] from JSON 
...TRUNCATED OUTPUT... 
[2012-12-08T22:54:16+01:00] INFO: Chef Run complete in 2.388374 
seconds 
[2012-12-08T22:54:16+01:00] INFO: Running report handlers 

solo.rb configures Chef-Solo to look for its cookbooks, roles, and data bags inside the current directory: the Chef repository.

Chef-Solo takes its node configuration from a JSON file. In our example, we called it node.json. If you're going to manage multiple servers, you'll need a separate file for each node. Then, Chef-Solo just executes a Chef run based on the configuration data found in solo.rb and node.json.

Advertisements