About

This is an intro to a functioning chef setup. I've added some customizations that I myself like, for instance my dotfiles, and installing vim with janus. This uses chef solo, with the knife-solo plugin.

Setup

  1. Clone this repository to your computer:
$ git clone git@github.com:blenderbox/chef-setup.git
  1. Go into the cloned directory. This will initialize the RVM and install the necessary gems. If you don't have RVM installed, install it, then go through the setup process, and finally cd out and back into the directory.
$ cd chef-setup
  1. Now install all of the chef cookbooks, which are managed with librarian.
$ librarian-chef install
  1. Optional: If you want to use this setup with Vagrant, I've created a Vagrantfile to make it smoother:
    • Install the vagrant gem.
    • Start up your new vagrant box.
    • Get the SSH connection string
$ gem install vagrant
$ vagrant up
$ vagrant ssh-config --host chef-setup > config.ssh

How To Use

  1. Once you've created a vanilla server, you'll want to prepare it for chef. You can do this with the knife prepare command. This command takes the host information as an argument. Assuming you've put your ssh configuration in a file called config.ssh, and your host is called chef-setup:
$ knife prepare chef-setup -F config.ssh
  1. Now your server has a chef installation on it, and it is ready to receive commands. Before we tell chef to install everything, we need to customize some settings. Check the available customizations below. At the very least, you'll have to add your pub key to data_bags/users/deploy.json.

  2. Now that you've added some customizations, you can go ahead and run:

$ knife cook chef-setup -F config.ssh nodes/default.json
  1. Once this is finished running, you'll have a fully operational server.

Customize

There's a lot of things you may want to customize with your chef setup. This only covers a few options that are specific to this project, for more info, consult the chef documentation, and take a look at all of the available cookbooks.

  • Users: The first thing you'll want to change are the users. As an example, there's one user that gets created called "deploy". To create more users, copy data_bags/users/deploy.json to data_bags/users/<username>.json. Then modify the "id" to match the name of the file, and update the ssh_keys array. To see more available configuration attributes, check the chef-user documentation.

  • Nodes: A node is the server you're setting up with chef. Once you run the knife prepare command, you'll notice that a new file has been created called nodes/<hostname>.json. Using nodes/default.json as a reference, you can add things to the run_list. For instance, if you've installed the php cookbook and you don't want to use the pythonapp role, your json file would look something like this:

{
      "run_list": [
         "role[base]",
         "role[appserver]",
         "recipe[php]"
      ]
}

Here, you can also modify default attributes of a recipe or a role. If you look at roles/base.rb you'll see several attributes being set inside the default_attributes call. For example, if you wanted to change the default shell for all users to sh:

{
      "user": { "default_shell": "/bin/sh" },
      "run_list": [...]
}