Skip to content

Instantly share code, notes, and snippets.

View jbz's full-sized avatar

J.B. Zimmerman jbz

View GitHub Profile
@jbz
jbz / userdata.sh.erb
Created August 2, 2011 20:42
EC2 userdata.sh script to install Chef and register with Chef server
#!/bin/bash
# User data to configure a vanilla Ubuntu EC2 instance.
# Installs chef-client (with minimal dependencies),
# configures chef, and adds roles
test $UID == 0 || (echo "Error: must run as root"; exit 1)
######### STEP 1: OPERATING SYSTEM CONFIGURATION
BOOTLOG="/var/log/bootstrap.log"
@jbz
jbz / userdata.sh.erb
Created August 2, 2011 20:41
EC2 userdata.sh script to install Chef and register with Chef server
#!/bin/bash
# User data to configure a vanilla Ubuntu EC2 instance.
# Installs chef-client (with minimal dependencies),
# configures chef, and adds roles
test $UID == 0 || (echo "Error: must run as root"; exit 1)
######### STEP 1: OPERATING SYSTEM CONFIGURATION
BOOTLOG="/var/log/bootstrap.log"
@jbz
jbz / gist:1090107
Created July 18, 2011 17:28
Script to parse chef nodes by last-checkin-time
#!/usr/bin/ruby
#
# Filter hosts wose time since last checkin >= X
#
# usage: (process that outputs lines) | filterHosts.rb <#hrs>
# to prune hosts in opscode: knife status *:* | filterHosts.rb <#hrs> | xargs -I % knife node delete % -y
STDIN.each_line {|line|
#split the line by commas, strip whitespace, map to fields
@jbz
jbz / On the client (default.rb in the cookbook)
Created June 22, 2011 15:14
Client/server config with chef
# Set attribute indicating munin role
node.set["munin"]["node"] = true
# Find available munin servers
available_servers = search(:node, "munin_server:true")
# Install munin plugins
munin_plugin "passenger_memory_stats"
munin_plugin "passenger_status"
node[:apt][:repo].each do |repo|
apt_repository repo[:name]
uri repo[:uri]
distribution repo[:dist]
components repo[:component]
action :add
end
end
domU-12-31-39-13-D8-C1% rsyslogd -v
rsyslogd 5.6.2, compiled with:
FEATURE_REGEXP: Yes
FEATURE_LARGEFILE: No
FEATURE_NETZIP (message compression): Yes
GSSAPI Kerberos 5 support: No
FEATURE_DEBUG (debug build, slow code): No
Atomic operations supported: Yes
Runtime Instrumentation (slow code): No
@jbz
jbz / knife.rb
Created February 16, 2011 17:08
knife.rb that switches Opscode orgs/validators based on git branch
# This knife.rb orig. provided by jtimberman@opscode.com - but any mistakes are mine!
current_dir = File.dirname(__FILE__)
platform = "https://api.opscode.com/organizations"
require 'grit'
branch = Grit::Repo.new("#{current_dir}/..").head.name
case branch
########################################################################
### NOTICE: this file managed by chef; changes made here will be lost.
########################################################################
# ubuntu defaults, left here for compatibility
root ALL=(ALL) ALL
%admin ALL=(ALL) NOPASSWD:ALL
# Amazon EC2 ubuntu user - DO NOT REMOVE FROM EC2 NODES
# ubuntu user is default user in ec2-images.
jzimmerman@ip-10-117-53-160:/etc/rsyslog.d$ sudo chef-client
[Wed, 26 Jan 2011 23:03:30 +0000] INFO: Starting Chef Run (Version 0.9.12)
[Wed, 26 Jan 2011 23:03:32 +0000] INFO: Writing updated content for template[/etc/rsyslog.d/nginx-main-error.conf] to /etc/rsyslog.d/nginx-main-error.conf
[Wed, 26 Jan 2011 23:03:32 +0000] INFO: template[/etc/rsyslog.d/nginx-main-error.conf] sending reload action to service[rsyslog] (delayed)
[Wed, 26 Jan 2011 23:03:32 +0000] ERROR: Running exception handlers
[Wed, 26 Jan 2011 23:03:32 +0000] ERROR: Exception handlers complete
/usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/runner.rb:53:in `run_action': undefined method `run_action' for "service[rsyslog]":String (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/runner.rb:101:in `converge'
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/runner.rb:97:in `each'
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/runner.rb:97:in `converge'
# from rsyslog::default.rb:
service "rsyslog" do
supports :restart => true, :reload => true
action [:enable, :start]
end
# from rsyslog/providers/imfile.rb: