Skip to content

Instantly share code, notes, and snippets.

@robbyt
robbyt / gist:846932
Created February 28, 2011 04:29
puppet 2.6 class example
class debian::apt($apt_ver='latest', $dpkg_ver='latest', $aptitude_ver='latest') {
package{'apt': ensure => $apt_ver;
'dpkg': ensure => $dpkg_ver;
'aptitude': ensure => $aptitude_ver;
}
}
case $cloud {
'rackspace': {
Host <<| tag == 'normal_server_private-rackspace' |>>
Host <<| tag == 'normal_server_public-us-east-1' |>>
Host <<| tag == 'normal_server_public-us-west-1' |>>
}
'ec2',default: {
@robbyt
robbyt / gist:1144587
Created August 14, 2011 04:31
Setup basic vagrant/vbox env
$apt_key = 'http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc'
file {'/etc/apt/sources.list.d/vargrant.conf':
ensure => file,
content => "deb http://download.virtualbox.org/virtualbox/debian ${lsbdistcodename} contrib",
notify => Exec['apt-get-update'],
before => Package['virtualbox-4.0'],
}
exec {'apt-key':
@robbyt
robbyt / gist:1156755
Created August 19, 2011 13:09
Test if perl script is running as root
#! /usr/bin/perl -w
use Carp;
my $username = getpwuid($<);
my $testuser = 'root';
if ( $username eq $testuser ){
print 'yep'
} else {
@robbyt
robbyt / gist:1574105
Created January 7, 2012 07:29
cloudfiles and eventlet
import eventlet
cloudfiles = eventlet.import_patched('cloudfiles')
username = 'foo'
api_key = 'bar'
buckets = ['list', 'of', 'buckets', 'to', 'create']
cf_pool = pools.Pool(create=lambda: cloudfiles.get_connection(username, api_key)
@robbyt
robbyt / starter.py
Created January 26, 2012 18:55
terminate a list of ec2 servers, passed in from stdin
#!/usr/bin/env python
import boto
import sys
ec2 = boto.connect_ec2()
# cat a file that contains ec2 instance ids into me and
# I will eat them up and turn them off
for instance in sys.stdin:
@robbyt
robbyt / clean.sh
Created February 8, 2012 21:31
puppet clean node
#!/bin/bash
if [ -z "$1" ]
then
echo "must feed me a FQDN of a server you want to delete!!!!"
exit 1
fi
/usr/bin/puppet node clean --unexport $1
/etc/puppet/tools/kill_node_in_storedconfigs_db.rb $1 > /dev/null
@robbyt
robbyt / boto-etag.py
Created February 23, 2012 23:14
boto etag hash auto verification
import boto
s3 = boto.connect_s3()
bucket = s3.get_bucket('robs-super-bucket')
d = bucket.new_key()
file1 = open('testfile.txt', 'r')
file2 = open('otherfile.txt', 'r')
# build the hash from file1
@robbyt
robbyt / centrify.rb
Created February 24, 2012 19:38
centrify fact for puppet
if File.exist?("/usr/bin/adinfo")
%x{/usr/bin/adinfo}.each do |line|
if line =~ /^(.+):(\s+)(.+)$/
var = $1; val =$3
# this will add centrify_ to each facter key, and
# replace spaces in the keys with _'s, and dropcase
Facter.add("centrify_" + var.gsub(/\s+/, "_").downcase()) do
setcode { val.chomp() }
end
@robbyt
robbyt / gist:2080034
Created March 18, 2012 19:25
Fix S3-based apt repos
echo "Acquire::http::Pipeline-Depth "0";" | sudo tee -a /etc/apt/apt.conf.d/90localsettings