Setting up Chef

1. First you need to install git as your version control system.[TERMINAL]

OSX: In OSX can install this with xcode .

xcode-select --install

2. Install wget to download the chef-repo template from the Opscode page[TERMINAL]


cd ~/Downloads
curl -O
tar -zxvf wget-1.15.tar.gz
cd wget-1.15/
./configure --with-ssl=openssl
sudo make install
rm -rf ~/Downloads/wget*

3. Set up up Github to store and manage your chef-repo and share it with others[TERMINAL]

ssh-keygen -t rsa -C "" #press just enter and when ask give type you passphrase
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
pbcopy < ~/.ssh/ #copies the key to your clipboard go to and set the key up there
ssh -T #test it

4. Set up chef-repo, download template from Obscode and upload it to github[TERMINAL]

cd ~/ #go to home directory
tar zvf master -x
mv opscode-chef-repo-f9d4b0c/ chef-repo
cd chef-repo/
git init .
git remote add origin
git add .
git commit -m "initial commit"
git push -u origin master

For a deep introduction to git and github I suggest

5. Install Chef on your terminal/workstation[TERMINAL]

This will download Ruby and all the required Ruby gems into /opt/chef/ embedded. By adding the /opt/chef/embedded/bin directory to your .bash_profile, the Chef command-line tools will be available in your shell.
cd ~/chef-repo/
curl -L | sudo bash
echo 'export PATH="/opt/chef/embedded/bin:$PATH"'>> ~/.bash_profile && source ~/.bash_profile

6. Setup a Chef Server on Obscode (alternatively you can set up your private hosted Chef server)[SERVER]

Go to Hosted Chef ( and sign up. After registering your account, it is time to prepare your organization to be used with your chef-repo repository.

Go to login and download the validation key and configuration file. Now regenerate the validation key for your organization and save it as <your- organization-short-name>.pem in the .chef directory inside your chef-repo repository. Also regenerate your user pulic key and save it in the .chef directory.

7. Create your cookbook[TERMINAL]

knife cookbook create my_cookbook

8. Upload your new cookbook to the Chef Server[TERMINAL]

knife cookbook upload my_cookbook

You can set up a node[NODE] via Vagrant here my example Vegrantfile:
Vagrant.configure("2") do |config| = "opscode-centos-7.0"
config.vm.box_url = ""
config.omnibus.chef_version = :latest
config.vm.provision :chef_client do |chef|
chef.provisioning_path = "/etc/chef"
chef.chef_server_url = ""
chef.validation_key_path = "~/chef-repo/.chef/dennisseidel-validator.pem"
chef.validation_client_name = "dennisseidel-validator"
chef.node_name = "server"

9. Add the cookbook to your node’s (here: server1) run list[TERMINAL]:

knife node run_list add server1 recipe[my_cookbook]

10. Run Chef Client on your node [NODE]

sudo chef-client

11. Install a community cookbook (iptables) [TERMINAL]

cd ~/chef-repo/
knife cookbook site install iptables

11. Upload cookbooks to chef server [TERMINAL]

knife cookbook upload --all

12. Manage cookbook dependencies with Berkshelf

cd ~/chef-repo/
vim Gemfile
bundle install

source ''
gem 'berkshelf'

Edit your cookbook’s metadata:
vim ~/chef-repo/cookbooks/my_cookbook/metadata.rb
depends 'chef-client'
depends 'yam'
depends 'ntp'

Edit your cookbook’s default recipe:
vim ~/chef-repo/cookbooks/my_cookbook/recipes/default.rb
include_recipe "chef-client"
include_recipe "yam"
include_recipe "ntp"

Create your Berksfile:
cd ~/chef-repo/
vim Berksfile

site :opscode


Leave a Reply