1/16/2016 - 7:41 AM

Cheat sheet for getting started with chef.

Cheat sheet for getting started with chef.

Chef Cheat sheet

Configuring Chef

To install stuff needed to run chef in a solo mode (Small one or two server configuration):

gem install knife-solo

To setup chef after it has been installed:

knife configure -r . --defaults 

How to Configure Virtual Box for testing Chef

Sidebar - in order to create a host-only network in virtual box, to make it easy to SSH into it from the host machine.

  • VirtualBox -> Preferences

  • Select Network

  • Push network card with "+" this creates a new Host-only network.

  • With the VM instance OFF:

    • Select VM Settings.
    • Select Adapter 2.
    • Toggle Enable Network Adapter.
    • Set Attached To: Host-only Adapter.
    • Name: The name of the host-only network created previously - default vboxnet0
    • Power up the VM.
  • You also need to make sure that the host-only network doesn't conflict with the IP address set to what you plan on using below.

    • Select the host-only adapter in VM settings.
    • Edit, make sure it doesn't conflict with the desired address ( for the below example).
  • Configure operating system as per normal. For Ubuntu:
  • sudo vim /etc/network/interfaces
  • Add the following: auto eth1 iface eth1 inet static

Cooking with Chef

To create a new 'kitchen' or chef project:

knife kitchen my_kitchen

Cookbooks, or predefined scripts for setting up a whole ton of cookbooks from different serverside tools can be found on github. However, before you can install cookbooks you must initialise your new kitchen as a git repository:

cd my_kitchen
git init
git add cookbooks/
git add data_bags/
git add nodes/
git add roles/
git add site-cookbooks/
git add solo.rb
git commit -a -m "Created new kitchen."

Then installing a particular preconfigured cookbook:

knife cookbook site install postgresql

To create a cookbook:

knife cookbook create widget

The cookbook then needs to be added to a run list. Run lists are on a server per server (node per node) basis. To prepare a new server (node) to receive a chef cookbook and create a run list:

knife solo prepare cfree@ 

To prepare a server with a different version of Chef (say to avoid compatibility cookbook compatibility issues) pass the omnibus version in:

knife solo prepare cfree@ --omnibus-version 10.24.0

Then to add postgresql to the run list, edit the newly created json file in nodes:

vim nodes/

It should contain the following, the run list instructs chef what recipes to invoke on the server when you cook, while the postgresql element is a configuration element required by the postgresql cookbook:

    "run_list": ["recipe[postgresql::server]"] 

Then cook the server using the following command:

knife solo cook cfree@