Skip to content

Instantly share code, notes, and snippets.

View fearoffish's full-sized avatar

Jamie van Dyke fearoffish

View GitHub Profile
class Chef
class Recipe
def run_for_instance_role(*roles, &block)
roles.map! {|a| a.to_s }
if roles.include?(node[:instance_role])
block.call
end
end
end
end
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
url = "http://bensbargains.net/rss.xml/0"
rss = Hpricot.XML(open(url))
links = rss.search("link")
task :env_1 do
role :web, '127.0.0.1'
role :app, '127.0.0.1'
role :db, '127.0.0.1', :primary => true
set :rails_env, 'production'
end
task :env_2 do
role :web, '127.0.0.1'
@fearoffish
fearoffish / open_ssh_terminals.rb
Created January 27, 2011 17:09
Used in conjunction with Opscode's knife, we can open new terminal tabs for every instance in a cluster of machines
# Requires Mac OS X and Opscode's Chef Platform
#
# So you use Opscode's knife tool (with Chef) and you use a naming convention for your instance node names:
# app1.testing.your-domain.com, db1.testing.your-domain.com etc.
#
# Then you can use this script with 'knife exec' to open a new terminal tab for each instance of that cluster,
# each of these tabs will open an ssh session to the machine.
#
# Run with:
# CLUSTER=testing knife open_ssh_terminals.rb

Start a feature branch based off the develop branch and do your changes.

git flow feature start some_new_things

Bump the version number of each cookbook you work on, major numbers are for api changes, minor numbers are for new features and release numbers are for bugfixes.

Environment files are where we control the version of cookbooks that run

@fearoffish
fearoffish / best_todos.coffee
Created May 23, 2011 14:11 — forked from jasonporritt/best_todos.coffee
Use @vars -- translation of Backbone.js example app
initialize: ->
@model.bind('change', @render)
@model.view = this
render: =>
$(@el).html(@template(@model.toJSON()))
@setContent()
return this
@fearoffish
fearoffish / gist:991604
Created May 25, 2011 18:41
Scout recipe and databag
## Recipe
# Grab our key details and user/group from the databag
scout_details = data_bag_item("scout", "main")
group scout_details["group"] do
action [ :create, :manage ]
end
user scout_details["user"] do
comment "Scout Agent"
@fearoffish
fearoffish / ubuntu10.04-ruby192.erb
Created July 20, 2011 17:15 — forked from hedgehog/ubuntu10.04-ruby192.erb
Ubuntu 10.04 + Ruby 1.9.2p180 chef bootstrap file
bash -c '
if [ ! -f /usr/local/bin/chef-client ]; then
apt-get update
apt-get -y upgrade
apt-get install -y build-essential wget zlib1g-dev libssl-dev libffi-dev curl bison build-essential autoconf libxml2-dev libreadline6-dev
cd /usr/src
wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p290.tar.bz2
tar xjf ruby-1.9.2-p290.tar.bz2
cd ruby-1.9.2-p290
./configure
class CreateMessages < ActiveRecord::Migration
def change
create_table :messages do |t|
t.string :subject
t.string :type
t.string :message
t.timestamps
end
end
end
@fearoffish
fearoffish / tag_instances
Created November 16, 2011 17:38
Take a chef node name and tag it as that on ec2
#!/bin/bash
# Grabs the list of nodes from chef and adds a tag for
# node_name to the appropriate instance
CMDNAME=tag_instances
TMPFILE=/tmp/${CMDNAME}.out.$$
ec2-describe-tags | grep node_name > $TMPFILE
retval=$?