ChefSnips

From Custard
Jump to: navigation, search

Install Chef Server under Debian

or

  • mkdir -p /etc/apt/trusted.gpg.d
  • gpg –keyserver keys.gnupg.net –recv-keys 83EF826A
  • gpg –export packages@opscode.com | tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null
  • apt-get update && apt-get upgrade
  • apt-get install opscode-keyring
  • apt-get install chef chef-server

or

  • sudo apt-get install chef chef-server-api chef-expander # No web UI

Chef Cookbooks

Download the opscode chef-repo structure

Create a Chef config

  • cd chef-repo
  • mkdir .chef
  • echo "cookbook_path [ '/root/chef-repo/cookbooks' ]" > .chef/knife.rb

Install a cookbook from the community site

  • knife cookbook site download apache2
  • tar zxf apache2*.tar.gz && rm apache2*.tar.gz


Create a cookbook

  • knife cookbook create my_app
  • vi metadata.rb
  • # Add depends "apache2"

This adds a dependency on the apache2 cookbook to our my_app cookbook.

  • vi recipes/default.rb
  • Add
include_recipe "apache2"

apache_site "default" do
  enable true
end


Spinning up an EC2 VM

Prerequisites

Set up aws access keys

# knife.rb

knife[:aws_access_key_id] = 'ACCESS_KEY_ID'
knife[:aws_ssh_key_id] = 'KEY_ID'
knife[:aws_secret_access_key] = 'SECRET_ACCESS_KEY'

Create an instance

knife ec2 server create \
  --availability-zone us-east-1d \
  --node-name test.pomegranate.ltd.uk \
  --flavor t1.micro \
  --image ami-fd20ad94 \
  --identity-file ~/.ssh/aws.pem \
  --run-list "role[my_app]" \
  --ssh-user ubuntu
Personal tools