Skip to content

Instantly share code, notes, and snippets.

View andrewgross's full-sized avatar

Andrew Gross andrewgross

View GitHub Profile
puts "Starting Bake"
puts config[:bake]
if config[:bake]
image_name = config[:bake]
puts image_name
image_description = (config[:run_list] || config[:role]).join(', ')
puts image_description
ami_info = connection.create_image(@server.identity, image_name, image_description)
puts ami_info.inspect
new_ami_id = ami_info.body['imageId']
@andrewgross
andrewgross / Makefile
Last active December 16, 2015 16:40
Makefile for Chef Repos
all: clean install
install:
bundle install
bundle exec berks install
test:
@bundle exec bash ${CHEF_PATH}/scripts/knife_test.sh
@bundle exec bash ${CHEF_PATH}/scripts/foodcritic_test.sh
@bundle exec bash ${CHEF_PATH}/scripts/rspec_test.sh
@andrewgross
andrewgross / chef.sh
Created April 26, 2013 02:34
Sampling of some Chef Glue
function download_cookbook() {
cookbook=${1}
if _check_input ${cookbook}
then
_clone_cookbook ${cookbook}
_link_cookbook_files ${cookbook}
cd ${CHEF_PATH}/cookbooks/${cookbook}
@andrewgross
andrewgross / ptbr_laugh.rb
Last active December 16, 2015 08:29
A useful function for anyone who works with brazilians.
def ptbr_laugh; (1..(1 + rand * 10)).map {("h" + ((rand * 4) + 1).to_i.times.map {%w(a e i o u)[rand * 5]}.join )}.join; end
@andrewgross
andrewgross / _install_from_source.rb
Created April 15, 2013 19:23
Remote File Pattern with Checksum Validation
url = node['redisio']['mirror']
base_name = node['redisio']['base_name']
version = node['redisio']['version']
extension = node['redisio']['artifact_type']
tarball_name = "#{base_name}#{version}"
tarball = "#{tarball_name}.#{extension}"
download_url = "#{url}/#{tarball}"
download_dir = node['redisio']['download_dir']
@andrewgross
andrewgross / _install_from_source.rb
Created April 15, 2013 19:08
Standard Remote File Download Pattern
url = node['redisio']['mirror']
base_name = node['redisio']['base_name']
version = node['redisio']['version']
extension = node['redisio']['artifact_type']
tarball_name = "#{base_name}#{version}"
tarball = "#{tarball_name}.#{extension}"
download_url = "#{url}/#{tarball}"
download_dir = node['redisio']['download_dir']
@andrewgross
andrewgross / free_attach_point.rb
Created April 10, 2013 20:48
Beware i wrote this over a year ago for ubuntu 12.04+ (note it uses xvd* instead of sd*)
def get_open_point(existing_device_prefix, new_device_range_start, new_device_range_stop)
# existing_device_prefix should be something like 'xvd' or 'md'
# new_device_range should be similar to '0' and '9' or 'f' and 'p'
possible_attach_points = (new_device_range_start..new_device_range_stop).map do |drive_letter|
"/dev/#{existing_device_prefix}#{drive_letter}"
end
Chef::Log.debug("#{@new_resource} Possible Attach Points: #{possible_attach_points}")
# Get a list of in use devices (fold numbered partitions together if looking at disk drives)
existing_devices = `ls /dev/#{existing_device_prefix}*`.split().each do |existing_device|
@andrewgross
andrewgross / magic.rb
Created April 9, 2013 22:12
A sample LWRP to mimic our HWRP
action :create do
# Some Chef Code
end
action :remove do
# Some more Chef code
end
@andrewgross
andrewgross / provider_magic.rb
Last active December 16, 2015 00:39
A simple provider in HWRP style
class Chef
class Provider
class CloudMagic < Chef::Provider
# We MUST override this method in our custom provider
def load_current_resource
# Here we keep the existing version of the resource
# if none exists we create a new one from the resource we defined earlier
@current_resource ||= Chef::Resource::CloudMagic.new(new_resource.name)
@andrewgross
andrewgross / magic.rb
Created April 9, 2013 21:25
A LWRP to mimic our HWRP
action :enable, :remove
default_action :enable
attribute :magic, kind_of => [TrueClass, FalseClass], :default => true
attribute :cloud, kind_of => String, :name_attribute => true