Skip to content

Instantly share code, notes, and snippets.

@zzondlo
zzondlo / default.rb
Created February 23, 2012 06:21 — forked from jonah-williams/default.rb
chef recipe to add delayed_job workers to monit to run them on Engine Yard cloud instances
#
# Cookbook Name:: delayed_job
# Recipe:: default
#
node[:applications].each do |app_name, data|
user = node[:users].first
case node[:instance_role]
when "solo", "app", "app_master"
@zzondlo
zzondlo / application_default.rb
Created February 23, 2012 06:32 — forked from rcreasey/application_default.rb
application::default
include_recipe "git"
node.run_state[:applications] = []
search(:apps) do |app|
(app["server_roles"] & node.run_list.roles).each do |app_role|
node.run_state[:applications] << {:app => app, :recipes => app["type"][app_role]}
end
end
{
"name": "webserver",
"default_attributes": {
"apache2": {
"listen_ports": [
"8080",
"443"
]
}
},
@zzondlo
zzondlo / Gemfile
Created March 31, 2012 21:53
rake script to switch chef servers and configure knife to use them
source 'http://rubygems.org'
gem 'colored'
gem 'escape'
gem 'facets'
gem 'extensions'
gem 'quality_extensions'
gem 'rscm'
gem 'termios'
gem 'net-ssh'
unless ARGV[0] && ARGV[1]
puts "Usage: set_password.rb username password"
exit 1
end
require 'chef'
require 'chef/config'
require 'chef/webui_user'
Chef::Config.from_file(File.expand_path("~/.chef/knife.rb"))
@zzondlo
zzondlo / base.rb
Created April 3, 2012 00:58 — forked from jtimberman/base.rb
an example roles/base.rb
name "base"
description "Baseline configuration for all systems."
run_list(
"recipe[ohai]",
"recipe[chef-client::delete_validation]",
"recipe[chef-client]",
"recipe[zsh]",
"recipe[git]",
"recipe[users]",
{
"id": "my_app"
"databases": {
"production": {
"encoding": "utf8",
"adapter": "mysql",
"username": "my_app",
"database": "production",
"password": "coolpassword"
},
@zzondlo
zzondlo / gist:2288462
Created April 3, 2012 01:01 — forked from jtimberman/gist:1051513
use run context in a recipe
ruby_block "config file" do
block do
run_context = Chef::RunContext.new(node, {})
r = Chef::Resource::File.new("#{node[:wordpress][:dir]}/wp-config.php", run_context)
r.content(IO.read("#{node[:wordpress][:dir]}/wp-config-sample.php"))
r.owner("root")
r.group("root")
r.mode("0644")
r.run_action(:create)
end
@zzondlo
zzondlo / etc_service.rb
Created April 3, 2012 01:10 — forked from tow/etc_service.rb
chef resource for a service running in /etc/service
define :etc_service, :action => :restart do
package "daemontools" do
action :install
end
path = params[:path] ? params[:path] : ("/etc/service/" + params[:name])
log_path = params[:log_path] ? params[:log_path] : ("/var/log/multilog/" + params[:name])
if params[:action] == :delete
directory path do
action :delete
recursive :true
define :sudo_user, :username => nil do
begin
r = resource(:template => "/etc/sudoers")
rescue
r = template "/etc/sudoers" do
source "sudoers.erb"
attributes { :users => [], :groups => [] }
end
end