Skip to content

Instantly share code, notes, and snippets.

@stefhen
stefhen / provision.rb
Last active August 29, 2015 14:02
CAT template provision example. Pass tasks back to global vars.
define launch_3_tier_v13_3(@srv_lb, @srv_app, @srv_db_master, @srv_db_slave, $staging) return @srv_lb, @srv_app, @srv_db_master, @srv_db_slave do
task_label("Launch 3-Tier Application")
# Since we want to launch these in concurrent tasks, we need to use global resources
# Tasks (like a "sub" of a concurrent block) get a copy of the resource scoped only
# to that task. Since we want to modify these particular resources, we copy them
# into global scope and copy them back at the end
@@launch_task_lb = @srv_lb
@@launch_db_master = @srv_db_master
@stefhen
stefhen / chef.rb
Created June 13, 2014 17:22
Get ec2 instance ID in Chef
node[:ec2][:instance_id]
@stefhen
stefhen / git.rb
Last active August 29, 2015 14:04
Git clone with Chef and ssh
# Install private key for git pull
file "/root/.ssh/git_ssh_key" do
content node[:ssh_key][:attribute]
mode "0400"
owner "root"
group "root"
end
git "/path/to/repo" do
repository "git://github.com/path/repo.git"
rightscale_marker :begin
log "Removing appserver IP address from firewall"
execute "iptables -D FWR -s #{node[:social][:ip_address_to_remove]} --destination 0.0.0.0/0 -p tcp --dport 5432 -j ACCEPT" do
cwd "/tmp"
end
rightscale_marker :end
@stefhen
stefhen / init.yml
Created August 28, 2014 02:15 — forked from renoirb/init.yml
Install automatically Oracle Java 7 under Salt Stack
#
# How to install automatically Oracle Java 7 under Salt Stack
#
# Thanks Oracle for complicating things :(
#
# 1. Create a java/ folder in your salt master
# 2. Paste this file in init.sls
# 3. salt '*' state.sls java
#
# Source:
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
@stefhen
stefhen / du.txt
Created October 26, 2014 17:34
aws cli s3 du
aws s3 ls s3://bucket --recursive | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024/1024" GB"}'
@stefhen
stefhen / presto.txt
Last active August 29, 2015 14:08
56 billion row query time with ORC and PrestoDB
presto:default> select count(*) from wiki_orc;
_col0
-------------
56521097302
(1 row)
Query 20141103_050649_00018_yw2uh, FINISHED, 40 nodes
Splits: 11,850 total, 11,850 done (100.00%)
1:06 [56.5B rows, 640GB] [861M rows/s, 9.76GB/s]
@stefhen
stefhen / haproxy.cfg
Created November 5, 2014 15:32
Custom haproxy configs
rspidel ^Server:.*
rspidel ^X-Powered-By:.*
option forwardfor
http-request set-header X-Forwarded-Proto https if { ssl_fc }
bind 0.0.0.0:443 ssl crt /usr/local/etc/haproxy/ssl_cert.pem
@stefhen
stefhen / cat_volume.rb
Created February 3, 2015 20:52
Create and attach EBS volume via CAT
#DEFINITIONS
define create_volume(@volume_1,$ebs_name,$counter) return @volume do
$volume_hash=to_object(@volume_1)
$volume_hash['fields']['name']=$ebs_name+'-'+$counter
@volume=$volume_hash
provision(@volume)
end
define attach_volume(@server,@volume,@volume_attachment_1) do
$va_hash=to_object(@volume_attachment_1)