Skip to content

Instantly share code, notes, and snippets.

View nathenharvey's full-sized avatar

Nathen Harvey nathenharvey

View GitHub Profile
@nathenharvey
nathenharvey / build-deb-ruby-1.9.2-p320.sh
Created May 8, 2012 10:51 — forked from jacobat/build-deb-ruby-1.9.2-p290.sh
i can has ruby-1.9.2 package with fpm
#!/bin/sh
rubyversion=1.9.2-p320
rubysrc=ruby-$rubyversion.tar.bz2
checksum=b226dfe95d92750ee7163e899b33af00
destdir=/tmp/install-$rubyversion
sudo apt-get -y install libssl-dev
gem list -i fpm || sudo gem install fpm --no-ri --no-rdoc
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "bento-12.04"
config.vm.box_url = "https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-ubuntu-12.04.box"
config.vm.forward_port 80, 8080
config.vm.customize [
"modifyvm", :id,

In the Chef Office Hours on December 20, 2012

Rob asked about getting chef installed on his server. We manually installed Chef there following the instructions at http://www.opscode.com/chef/install/ and then ran a knife bootstrap command. The easier way would have been to simply run the knife bootstrap command.

For example after launching a fresh instance on EC2, I can simply run:

$ knife bootstrap ec2-184-73-68-244.compute-1.amazonaws.com -x ubuntu -i ~/.aws/nharvey-aws.pem --sudo

-x is the username I'll login with: ubuntu
-i is the identify file I'll use when logging in: ~/.aws/nharvey-aws.pem

Pre-requisites

  1. Install an application that you'll use to ssh, if you don't already have one (OpenSSH, puTTY, etc.)

  2. Install a programmer's text editior, if you don't already have one (Vi/Vim, Emacs, Sublime Text 2, etc.)

  3. Install Chef Client on your local workstation

  • Not currently using Ruby? Install using the Opscode Installer
  • Currently using Ruby with a version manager like rvm or rbenv? gem install chef --version 11.4.0 --no-ri --no-rdoc
echo "Installing Chef $version"
case "$filetype" in
"rpm") rpm -Uvh "$tmp_dir/$filename" ;;
"deb") dpkg -i "$tmp_dir/$filename" ;;
"solaris") echo "conflict=nocheck" > /tmp/nocheck
echo "action=nocheck" >> /tmp/nocheck
pkgadd -n -d "$tmp_dir/$filename" -a /tmp/nocheck chef
;;
"sh" ) bash "$tmp_dir/$filename" ;;
esac
@nathenharvey
nathenharvey / knife.rb
Created July 25, 2013 16:07
A Chef knife.rb that uses the git gem to determine which git branch you're in and then updates the Chef server endpoint accordingly.
require 'rubygems'
require 'git'
g = Git.open('./')
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name 'myworkstation'
cache_type 'BasicFile'
$ chef-solo -c solo.rb -j node.js -l debug
[2013-08-14T19:11:21+00:00] INFO: *** Chef 0.10.8 ***
[2013-08-14T19:11:22+00:00] DEBUG: Building node object for nharveylearnchef02-starter
[2013-08-14T19:11:22+00:00] DEBUG: Extracting run list from JSON attributes provided on command line
[2013-08-14T19:11:22+00:00] INFO: Setting the run_list to "recipe[file_test]" from JSON
[2013-08-14T19:11:22+00:00] DEBUG: Applying attributes from json file
[2013-08-14T19:11:22+00:00] DEBUG: Platform is ubuntu version 12.04
[2013-08-14T19:11:22+00:00] INFO: Run List is [recipe[file_test]]
[2013-08-14T19:11:22+00:00] INFO: Run List expands to [file_test]
[2013-08-14T19:11:22+00:00] INFO: Starting Chef Run for nharveylearnchef02-starter
@nathenharvey
nathenharvey / chef-client.log
Created September 11, 2013 00:59
chef-client -l debug output from the Chef Fundamentals class.
[2013-09-10T13:20:44+00:00] INFO: Forking chef instance to converge...
[2013-09-10T13:20:44+00:00] DEBUG: Fork successful. Waiting for new chef pid: 4549
[2013-09-10T13:20:44+00:00] DEBUG: Forked instance now converging
[2013-09-10T13:20:44+00:00] INFO: *** Chef 11.6.0 ***
[2013-09-10T13:20:44+00:00] DEBUG: Loading plugin os
[2013-09-10T13:20:44+00:00] DEBUG: Loading plugin kernel
[2013-09-10T13:20:44+00:00] DEBUG: Loading plugin ruby
[2013-09-10T13:20:44+00:00] DEBUG: Loading plugin languages
[2013-09-10T13:20:44+00:00] DEBUG: ---- Begin ruby -e "require 'rbconfig'; puts %Q(platform=#{RUBY_PLATFORM},version=#{RUBY_VERSION},release_date=#{RUBY_RELEASE_DATE},target=#{::Config::CONFIG['target']},target_cpu=#{::Config::CONFIG['target_cpu']},target_vendor=#{::Config::CONFIG['target_vendor']},target_os=#{::Config::CONFIG['target_os']},host=#{::Config::CONFIG['host']},host_cpu=#{::Config::CONFIG['host_cpu']},host_os=#{::Config::CONFIG['host_os']},host_vendor=#{::Config::CONFIG['host_vendor']},bin_dir=#{::Config::CO
@nathenharvey
nathenharvey / failed execute resource
Created September 19, 2013 23:13
example of a failed 'execute' resource. This will cause the chef-client run to fail and throw an exception.
cookbooks/foo/recipes/default.rb
#
# Cookbook Name:: foo
# Recipe:: default
#
# Copyright 2013, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
data_bag("vhosts").each do |site|
site_data = data_bag_item("vhosts", site)
site_name = site_data["id"]
document_root = "/srv/apache/#{site_name}"
template "/etc/apache2/sites-available/#{site_name}" do
source "custom-vhost.erb"
mode "0644"
variables(
:document_root => document_root,