Skip to content

Instantly share code, notes, and snippets.

View mpasternacki's full-sized avatar

Maciej Pasternacki mpasternacki

View GitHub Profile
@mpasternacki
mpasternacki / reap_instances.rake
Created January 16, 2011 20:03
Reap Node and Client instances for dead EC2 instances on a chef server.
# -*- mode: ruby; coding: utf-8 -*-
# Requires fog gem.
# Configure AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in config/rake.rb
desc <<EOF
Delete nodes and clients for nonexistent EC2 instances from chef server
YES=1 variable makes task skip confirmation questions.
EOF
@mpasternacki
mpasternacki / update_dns.rake
Created February 1, 2011 13:36
Rake task to update Amazon Route53 DNS from by Chef node search
# -*- ruby -*-
# Needs following parameters configured in rake.rb:
# DNS_DOMAIN: domain for which to set entries, including trailing dot
# (e.g. "example.com.")
# DNS_ATTRIBUTE: attribute containing hostname to CNAME to, defaults
# to 'fqdn'; for EC2, use "ec2.public_hostname"
# DNS_ENTRIES: hash mapping hostname to node search query,
# e.g. {'buildbot' => 'recipes:buildbot', 'monitoring' =>
# 'roles:monitoring'}
@mpasternacki
mpasternacki / shef.rb
Created February 3, 2011 12:50
Make shef try to load current knife config by default
# ~/.chef/shef.rb
begin
# Load configuration from knife.rb
require 'chef/knife'
Chef::Knife.new.configure_chef
rescue
puts <<-EOF
Can't load knife config: #{$!}
This is probably nothing serious.
EOF
@mpasternacki
mpasternacki / backports_apt_package.rb
Created February 9, 2011 17:53
Debian backports package resource for Opscode Chef
# backports_apt_package.rb
#
# Resource and provider to correctly install packages from Debian's
# backports, which are a non-default apt source. Creates
# backports_apt_package resource which does the Right Thing.
#
# Drop this file into cookbook's libraries/ dir.
require 'chef/provider/package/apt'
require 'chef/resource/package'
@mpasternacki
mpasternacki / chef_fileedit_g.rb
Created April 15, 2011 17:55
Add g method (named after (s)ed's g//) to Chef::Util::FileEdit for more flexible text manipulation
class Chef
class Util
class FileEdit
public
# Run block for matching lines, passing it matching line.
# Replaces matching lines with value returned by the block.
def g(regex)
exp = Regexp.new(regex)
new_contents = []
contents.each do |line|
@mpasternacki
mpasternacki / knife.rb
Created October 21, 2011 11:59
Make Chef's `knife ssh` use your actual login name
# knife.rb config snippet to make knife ssh command use your own login
# instead of hard-coded `root', `ubuntu' or other name. Tries to get
# login for your domain from ~/.ssh/config and if it's not found
# there, uses your local login.
require 'net/ssh'
require 'etc'
knife[:ssh_user] =
Net::SSH::Config.for('some.host.inside.your.domain')[:user] ||
@mpasternacki
mpasternacki / check_with_hysteresis.pl
Created December 23, 2011 23:49
Hysteresis support for nagios service checks' limit
#!/usr/bin/perl -w
#
# check_with_hysteresis.pl - hysteresis for nagios service checks' limits
#
# Usage: check_with_hysteresis.pl $LASTSERVICESTATE$ default check --- STATE1 check for state1 --- STATE2 check for state2 ...
#
# If $LASTSERVICESTATE$ is STATE1, "check for state1" will be
# executed, if it's STATE2, "check for state2" will be executed, and
# so on; if state is undefined, "default check" wil be executed.
#
@mpasternacki
mpasternacki / perl_module_build.rb
Created December 29, 2011 21:59
Opscode Chef definition to upgrade Module::Build using perl cookbook's cpan_install script
# Example usage:
# perl_module_build "0.3601"
define :perl_module_build do
execute "/usr/local/bin/cpan_install Module::Build" do
cwd "/root"
path [ "/usr/local/bin", "/usr/bin", "/bin" ]
not_if { `perl -mModule::Build -e 'print $Module::Build::VERSION'`.to_f >= params[:name].to_f }
end
end
@mpasternacki
mpasternacki / google-multilogin.scpt
Created April 28, 2012 23:40
AppleScript to consistently log into multiple Google Apps account in Safari
on js(jscpt)
set jscpt to "(function _l () {" & jscpt & "}());"
tell application "Safari" to do JavaScript jscpt in document 1
end js
on log_into_google(method, username, password)
tell application "Safari" to set URL of document 1 to "https://accounts.google.com/" & method
delay 2
js("var f = document.getElementById('gaia_loginform');
f.Email.value = '" & username & "';
@mpasternacki
mpasternacki / 00-packages_builder.rb
Created May 29, 2012 09:44
Debian packaging continuous integration
# Chef resources describing how to set up package repository server,
# simplified fromactual cookbook (not open sourced yet). Sets up apt
# repository in /srv/apt directory, with system user "apt-repo". Packages
# are GPG-signed to prevent apt-get from complaining on every install.
#
# Directory /srv/apt should be reachable to clients via http or other
# means. This is left as an exercise for the reader.
#
# For extra explanations, see:
# http://joseph.ruscio.org/blog/2010/08/19/setting-up-an-apt-repository/