Skip to content

Instantly share code, notes, and snippets.

View danielsdeleo's full-sized avatar

Dan DeLeo danielsdeleo

View GitHub Profile
@danielsdeleo
danielsdeleo / gist:3063064
Created July 6, 2012 22:17
Knife Role Tree example output
ddeleo@boltzmann chef git:(master)> bin/knife role tree $node_name
top level
|-role[preprod]
| |-recipe[network]
| |-recipe[splunk42]
|-role[mysql-master]
| |-role[base]
| | |-role[platform-annoyances]
| | | |-recipe[platform-specific]
| | | |-recipe[selinux::disabled]
@danielsdeleo
danielsdeleo / gist:2920702
Created June 12, 2012 23:06
Eval and Converge a Single Chef Recipe
#!/usr/bin/env ruby
recipe_path = ARGV[0]
if recipe_path.nil?
STDERR.puts "usage: chef-apply RECIPE_FILE"
exit 1
end
recipe_path = File.expand_path(recipe_path)
@danielsdeleo
danielsdeleo / resource_display.rb
Created May 22, 2012 19:45
Print a list of resources with the attributes filled in from node attrs, search, etc.
# (sudo) knife exec -c /etc/chef/client.rb resource_display.rb [FILTER]
# This will update the recipes and such on your machine, but it shouldn't make any real changes.
# Coded in 10 minutes, use at your own risk.
require 'chef/client'
require 'chef/checksum_cache'
require 'chef/provider'
require 'chef/providers'
require 'chef/resource'
require 'chef/resources'
@danielsdeleo
danielsdeleo / rbcompile.rb
Created December 20, 2011 19:27
Gem load path compiler for ruby CLI applications
require 'pp'
require 'fileutils'
require 'rubygems'
# ==HAX WARNINGS:
# * this does some terrible things, like using a regex to prevent rubygems from
# loading at all. This will be made non-terrible in the future.
# * Dependency resolution is amateur hour. This will also be made non terrible
# in the future.
# ==Philosopy
@danielsdeleo
danielsdeleo / k.rb
Created December 16, 2011 22:13
A wrapper for Chef's `knife` that saves you typing
#!/usr/bin/env ruby
#= k
#== Requirements
# I install Chef with rubygems. May/may not work with other install methods.
#
#== INSTALL
# copy this to ~/bin/k
#
#== USE
# recipe A
template "authorized_keys" do
variables :two_factor => false, :foo => "bar"
# other stuff
end
# 2 factor auth recipe
template "authorized_keys" do
variables(Hash.new) if variables.nil?
link "/tmp/foo" do
to "/tmp/bar"
end
log "this is a message" do
action :nothing
end
link_resource = resources(:link => "/tmp/foo")
gem_package("some-gem") do
action(:nothing)
run_action(:install)
end
Gem.clear_paths
require 'some-gem'
#!/usr/bin/env ruby
require 'benchmark'
require 'optparse'
require 'pp'
require 'rubygems'
require 'yajl'
require 'chef/rest'
module CGrep
class Config
require 'pp'
require 'thread'
class Result < Queue
def to_a
@que
end
end
class Titerator