Spaghetti Programming

The Shortest Chef Solo How To

chef solo how to

Preface

This is a quick and basic guide I wrote that will get the opscode tool chef solo running in about 10 minutes. There are some paths and names in this guide that are specific to my use case. Obviously those would need to be changed for your environment.

1. Download and install chef

curl -L https://www.chef.io/chef/install.sh | sudo bash -s -- -v 12.3

2. Install git and clone the chef-repo

sudo apt-get install git
git clone https://github.com/opscode/chef-repo
#optionally change the remote origin url to your repo
cd chef-repo
git remote set-url origin git@github.com:MatthewRamirez/chef-repo.git

3. Create the file ~/chef-repo/solo.rb with the contents

file_cache_path "/home/matt/chef-repo"
cookbook_path "/home/matt/chef-repo/cookbooks"
json_attribs "/home/matt/chef-repo/node.json"

4. Create the file ~/chef-repo/node.json with the contents

{
  "run_list": [
    "recipe[cookbook_name::recipe_name]"
    "recipe[some_other_cookbook]"
  ]
}

5. (Optional) If you want to use knife commands like

knife cookbook create my_new_cookbook
knife cookbook site download apt

Then you will probably want to create the file ~/.chef/knife.rb.

log_level                :info
log_location             STDOUT
node_name                'ubuntu'
syntax_check_cache_path  '/home/matt/.chef/syntax_check_cache'
cookbook_path            '/home/matt/chef-repo/cookbooks'
cookbook_license         'Proprietary - All Rights Reserved'
cookbook_copyright       'Spaghetti Programming'
cookbook_email           'myemail@email.com'

7. Use this command to start chef-solo and execute the run list in node.js

sudo chef-solo -c ~/chef-repo/solo.rb

8. Edit ~/chef-repo/node.json

As you download new cookbooks from the opscode community site using knife or write your own, be sure to update the node.json with any new cookbooks you want to be included in the run list for your node.

Optional Steps to Encrypt Data Bags with Knife Solo

1. Install knife solo gems to work with encrypted data bags

You must use the gem command that is installed by the opscode chef installer in /opt to do the install.

sudo /opt/chef/embedded/bin/gem install knife-solo
sudo /opt/chef/embedded/bin/gem install knife-solo_data_bag

2. Generate encryption secret

openssl rand -base64 2048 > ~/.chef/encrypted_data_bag_secret

3. Add encrypted_data_bag_secret directive inside knife.rb

encrypted_data_bag_secret '/home/matt/.chef/encrypted_data_bag_secret'

4. Create encrypted data bags

You can create/view/edit encrypted data bags with the following commands

knife solo data bag create data_bag_name data_bag_id

knife solo data bag show data_bag_name data_bag_id

knife solo data bag edit data_bag_name data_bag_id