Skip to content

Instantly share code, notes, and snippets.

View srinivasmohan's full-sized avatar

Srinivasan Mohan srinivasmohan

View GitHub Profile
@srinivasmohan
srinivasmohan / deb_via_dpkg_provider.rb
Created September 1, 2012 00:07
Install local deb via Chef::Provide Dpkg
#Cookbook_file section same as before
package 'glusterfs_3.2.1-1_amd64.deb' do
provider Chef::Provider::Package::Dpkg
source "/var/chef-package-cache/glusterfs_3.2.1-1_amd64.deb"
action :install
end
@srinivasmohan
srinivasmohan / updhosts.rb
Created December 17, 2012 21:08
Update /etc/hosts based on a template usinf Knife/Chef provided info.
#Rebuild hosts file from knife node list,
require 'erb'
require 'json'
require 'ohai' #to find my own IP
def myaddress
thissys=Ohai::System.new
thissys.all_plugins
myip=thissys['cloud']['private_ips'][0]
return myip
@srinivasmohan
srinivasmohan / hosts.erb
Created December 17, 2012 21:09
Hosts.erb template for updhosts.rb
#Last updated <%= Time.now.to_s %> by '<%= $0.split('/')[-1] %> <%= ARGV[0] %> <%= ARGV[1] %>'
127.0.0.1 localhost
<%= myip_ohai %> my_mgmt_host
#Static entries...
#...
#...
#The following are chef managed instances whose IPs are pulled from knife exec runs.
##All of the below are generated from template entry in /etc/hosts.erb
<% %w{server1 server2 server3}.sort.each do |thissvr| %>
@srinivasmohan
srinivasmohan / awscreds_from_databag.rb
Created May 30, 2013 11:48
Pull config info for a script from a chef data bag (So your script runs via "knife exec" without embedding config info in it)
#This is meant to be run via "knife exec scriptname.rb"
#
require 'fog'
#Make sure you have a data bag called admin/ec2creds containing values 'aws_access_key_id' and 'aws_secret_access_key'
#which point to your AWS access key and secret access key.
DBAG_NAME='admin'
DBAG_KEY='ec2creds'
#Pull AWS credentials from the databag 'admin' with key 'ec2creds'
aws=Chef::DataBagItem.load(DBAG_NAME,DBAG_KEY)
@srinivasmohan
srinivasmohan / uri-encode
Created August 2, 2013 20:18
Add to unsafe characters to force them to be encoded - Ruby 1.9.x URI.
[smohan@dhcpa-111 ~]$ irb
irb(main):001:0> require 'uri'
=> true
irb(main):002:0> p URI::Parser.new.regexp[:UNSAFE]
/[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]/
=> /[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]/
irb(main):003:0> p Regexp.union([URI::Parser.new.regexp[:UNSAFE],'~','@'])
/(?-mix:[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]])|~|@/
=> /(?-mix:[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]])|~|@/
irb(main):004:0>
@srinivasmohan
srinivasmohan / versal-ubuntu1204lts.sh
Created October 10, 2013 00:02
Prebuild chef ready AMI
#!/bin/bash
#Run this on AMI ami-7e2da54e in us-west-2 (Supply this script as userdata) and build an AMI from the resulting instance.
#VPC Bootstrap User-data script generated at 2013-10-09 16:56:44 -0700
function logmsg {
echo "CHEF-VPC-INIT: $1"
}
CHEF_VERSION=11.6.0
RUBY_GEM_VER=1.8.25
@srinivasmohan
srinivasmohan / chefsvr-nginx-ssl.conf
Created August 15, 2012 22:30
Nginx SSL Hosts config to make chefs web GUI and REST API available over SSL
###Nginx config to make Chef servers WebGUI (localhost:4040) and
###REST API (localhost:4000) both available over SSL in the same vhost.
#If your SSL certificate requires a CA Cert bundle, then you may also need to install/symlink a copy of the
#bundle pem in folder /etc/ssl/certs/ and run "c_rehash /etc/ssl/certs/" on the machines that
#need to access these SSL endpoints.
# This is typically needed for RapidSSL/Geotrust issued SSL certificates, YMMV.
#I have these upstreams in the main nginc.conf:
#rest api
upstream chef_webui {
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@srinivasmohan
srinivasmohan / thumbnail.rb
Created September 4, 2014 19:12
ffmpeg screenshots
#!/usr/bin/ruby
require "streamio-ffmpeg"
class Video
def initialize(f="", outf="./", at=[20, 50, 80])
@video=FFMPEG::Movie.new(f)
@at=at.map { |x| (@video.duration*x/100).to_i}
$stderr.puts "Video #{f} (#{@video.duration} secs) - Screenshots at #{@at.inspect}"
@outf=outf
@srinivasmohan
srinivasmohan / hipchat_notify.rb
Created April 19, 2012 05:32
Post Nagios alerts to Hipchat
#!/usr/bin/ruby
require 'rubygems'
require 'hipchat-api'
require 'getopt/long'
require 'socket'
require 'erb'
#Do not modify these constants! (after you set these up, of course)
HipApiKey='ABCDEFGHKJHKJHKJHKJH'
Room='Nagios'