Chef Solo

Chef-Solo

Chef-Solo allows you to run cookbooks with nodes without requiring access to Chef Server (Client-Server Configuration). It allows you to install, configure and manage packages within your nodes easily.

Getting started with Chef-Solo

Install Chef

curl -L https://www.opscode.com/chef/install.sh | bash

Project Setup

Create New Project Structure for Chef-Solo

  • knife solo init <Directory>
/home/vagrant/chef/chef-repo

|-- chefignore
|-- cookbooks
|   |-- apache2
|   |-- myapp
|   `-- README.md
|-- data_bags
|   `-- README.md
|-- environments
|   `-- README.md
|-- LICENSE
|-- README.md
|-- roles
|   `-- README.md
|-- solo.rb
`-- web.json

Create a knife.rb for the Solo Project under .chef

/home/vagrant/chef/chef-repo/.chef$ cat knife.rb
cookbook_path [ '/home/vagrant/chef/chef-repo/cookbooks' ]

Create Your CookBook

knife cookbook create myapp

Download / Install Dependent cookbooks

Downloads a Tar Ball

knife cookbook site download apache2

Installs via Git

knife cookbook site install nodejs

Update Cookbook

  • Update metadata.rb to add dependency

vagrant@precise64:~/chef/chef-repo/cookbooks/myapp$ cat metadata.rb

depends "apache2"
  • Add apache2 receipe to myapp

vagrant@precise64:~/chef/chef-repo/cookbooks/myapp/recipes$ cat default.rb

include_recipe "apache2"

apache_site "default" do
  enable true
end
  • Update Attributes

vagrant@precise64:~/chef/chef-repo/cookbooks/myapp/attributes$ cat default.rb

default['apache']['default_site_enabled'] = true

Create Chef-Solo Configuration File

vagrant@precise64:~/chef/chef-repo$ cat solo.rb

file_cache_path "/root/chef-solo"
cookbook_path "/home/vagrant/chef/chef-repo/cookbooks"

Create Chef-Solo Attribute File

vagrant@precise64:~/chef/chef-repo$ cat web.json

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

Installs Chef on Target Host

knife solo prepare <User>@<Host>
knife solo prepare vagrant@192.168.33.12

Uploads cookbook to Target Host

knife solo cook vagrant@192.168.33.12

Code available on https://github.com/arttuladhar/chef-solo-repo

  • https://gist.github.com/arttuladhar/d744c97e9dec50ad77b1
  • http://gettingstartedwithchef.com/first-steps-with-chef.html
  • https://adamcod.es/2013/06/04/deploy-a-basic-lamp-stack-digital-ocean-chef-solo.html