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]

OSX:

cd ~/Downloads
curl -O http://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz
tar -zxvf wget-1.15.tar.gz
cd wget-1.15/
./configure --with-ssl=openssl
make
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 "den.seidel@gmail.com" #press just enter and when ask give type you passphrase
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
pbcopy < ~/.ssh/id_rsa.pub #copies the key to your clipboard go to github.com and set the key up there
ssh -T git@github.com #test it

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

cd ~/ #go to home directory
wget http://github.com/opscode/chef-repo/tarball/master
tar zvf master -x
mv opscode-chef-repo-f9d4b0c/ chef-repo
cd chef-repo/
git init .
git remote add origin git@github.com:den53/chef-repo.git
git add .
git commit -m "initial commit"
git push -u origin master

For a deep introduction to git and github I suggest https://www.udacity.com/course/ud775

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 https://www.opscode.com/chef/install.sh | 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 (https://www.getchef.com/chef/choose-your-version/) and sign up. After registering your account, it is time to prepare your organization to be used with your chef-repo repository.

Go to http://manage.opscode.com/organizations 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|
config.vm.box = "opscode-centos-7.0"
config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-7.0_chef-provisionerless.box"
config.omnibus.chef_version = :latest
config.vm.provision :chef_client do |chef|
chef.provisioning_path = "/etc/chef"
chef.chef_server_url = "https://api.opscode.com/organizations/dennisseidel"
chef.validation_key_path = "~/chef-repo/.chef/dennisseidel-validator.pem"
chef.validation_client_name = "dennisseidel-validator"
chef.node_name = "server"
end
end

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

Gemfile:
source 'https://rubygems.org'
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

metadata

Leave a Reply