Skip to content

Instantly share code, notes, and snippets.

@stefhen
stefhen / generate_ssh_keys.rb
Created June 25, 2012 17:59 — forked from 3dd13/generate_ssh_keys.rb
chef recipe to generate ssh key for a user
define :generate_ssh_keys, :user_account => nil do
username = params[:user_account]
raise ":user_account should be provided." if username.nil?
Chef::Log.debug("generate ssh skys for #{username}.")
execute "generate ssh skys for #{username}." do
user username
creates "/home/#{username}/.ssh/id_rsa.pub"
@stefhen
stefhen / creds.sh
Last active October 7, 2015 19:07
export creds
#!/bin/bash
echo $AWS_ACCOUNT >> /tmp/cred.txt
echo $AWS_ACCESS_KEY_ID >> /tmp/cred.txt
echo $AWS_SECRET_ACCESS_KEY >> /tmp/cred.txt
@stefhen
stefhen / query.rb
Last active October 9, 2015 13:57
Query deployment for tags
seed_hosts = rightscale_server_collection "seed_hosts" do
tags ["cassandra:seed_host=true"]
mandatory_tags ["server:private_ip_0"]
empty_ok false
action :nothing
end
seed_hosts.run_action(:load)
seed_ips = Array.new
@stefhen
stefhen / set-rrd.py
Created March 12, 2013 18:41
Change all S3 objects to REDUCED_REDUNDANCY
#!/usr/bin/env python
import boto
s3 = boto.connect_s3()
b = s3.lookup('BUCKET_NAME_HERE')
[x.change_storage_class('REDUCED_REDUNDANCY') for x in b.get_all_keys()]
@stefhen
stefhen / gen_inputs.rb
Last active December 17, 2015 21:19
Generate RightScale metadata.rb input code
#!/usr/bin/env ruby
require 'highline/import'
attr = ask "attribute: "
desc = ask "description: "
recipes = ask "recipes: "
type = ask ("type: ") { |q| q.default = "string" }
disp = ask ("display_name: ") { |q| q.default = attr }
required = ask ("required: ") { |q| q.default = "required" }
@stefhen
stefhen / ros_util.rb
Created November 7, 2013 20:49
ROS util example
bash "download_rpm" do
code <<-EOM
export STORAGE_ACCOUNT_ID="#{node[:smartfox][:storage_account_id]}"
export STORAGE_ACCOUNT_SECRET="#{node[:smartfox][:storage_account_secret]}"
/opt/rightscale/sandbox/bin/ros_util get -c "#{node[:smartfox][:bucket]}" -s "#{node[:smartfox][:file]}" -C "#{node[:smartfox][:provider]}" -d "#{Chef::Config[:file_cache_path]}/#{node[:smartfox][:file].split('/').last}"
EOM
end
@stefhen
stefhen / ips.rb
Created December 10, 2013 18:41
Get public and private IP's of currently running server.
log "PUBLIC IP: #{node[:cloud][:public_ips][0]}\n"
log "PRIVATE IP: #{node[:cloud][:private_ips[0]}\n"
@stefhen
stefhen / tag-search-examples.rb
Created March 6, 2014 20:13
RightScale tag searching examples
# Obtain information about Jenkins master by querying for its tags
r = rightscale_server_collection "master_server" do
tags "jenkins:master=true"
mandatory_tags "jenkins:active=true"
action :nothing
end
r.run_action(:load)
master_ip = ""
master_port = ""
@stefhen
stefhen / del_s3.py
Created April 10, 2014 21:39
Mass delete s3 keys
#!/usr/bin/env python
import boto
s3 = boto.connect_s3()
bucket = s3.get_bucket("bucket")
rs = bucket.list(prefix="key/prefix/here")
result = bucket.delete_keys([key.name for key in rs])
# In Chef, when a resource is defined all its variables are evaluated during
# compile time and the execution of the resource takes place in converge phase.
# So if the value of a particular attribute is changed in converge
# (and not in compile) the resource will be executed with the old value.
# Example problem:
# Let's consider this situation where there are two steps involved in a recipe
# Step 1 is a Ruby block that changes a node attribute. Rubyblocks get executed
# in converge phase
# Step 2 is a Chef resource that makes use of the node attribute that was