Skip to content

Instantly share code, notes, and snippets.

View jonlives's full-sized avatar

Jon Cowie jonlives

View GitHub Profile
<command>
<ident value="only_if">
<pos line="38" column="2"/>
</ident>
<args_add_block value="false">
<args_add>
<args_new/>
<string_literal>
<string_add>
<string_add>
execute "generate_csr" do
user "root"
cwd "/tmp/"
command "<snip>"
only_if {!File.exists?(foo) || (File.exists?(bar) && File.mtime(baz) < last_changedate)}
end
rule "ETSY004", "Execute resource defined without conditional or action :nothing" do
tags %w{correctness recipe etsy}
recipe do |ast|
pres = find_resources(ast, :type => 'execute').find_all do |cmd|
not_if = (resource_attribute(cmd, 'not_if') || "").to_s
only_if = (resource_attribute(cmd, 'only_if') || "").to_s
creates = (resource_attribute(cmd, 'creates') || "").to_s
action = creates = (resource_attribute(cmd, 'action') || "")
(not_if.empty? && only_if.empty? && creates.empty?)
end.map{|cmd| match(cmd)}
require 'chef/knife'
module KnifeSpork
class Testy < Chef::Knife
banner "knife test"
def run
@response = ui.ask_question("What is your name?")
r = gem_package "sys-proctable" do
action :nothing
end
r2 = gem_package "sys-filesystem" do
action :nothing
end
r.run_action(:install)
r2.run_action(:install)
@jonlives
jonlives / cache_helper.rb
Created January 22, 2012 14:19 — forked from bryanthompson/cache_helper.rb
Simple fragment caching in sinatra
require 'sinatra/base'
class CacheHelper
module Sinatra
module Helpers
def cache(name, options = {}, &block)
if cache = read_fragment(name, options)
@_out_buf << cache
else
pos = @_out_buf.length
{
"name": "Base",
"description": "Base Role!",
"json_class": "Chef::Role",
"default_attributes": {
},
"override_attributes": {
"ganglia": {
"mcast_addr": "1.2.3.4",
"cluster_name": "foo"
@jonlives
jonlives / gist:1486734
Created December 16, 2011 16:30
Bootstrap Manifest for Chef on OS X
bash -c '
cd ~/Desktop
curl -O http://joncowie.local/xcode.tar.gz
tar -zxf xcode.tar.gz
installer -pkg ~/Desktop/Install\ Xcode.app/Contents/Resources/Xcode.mpkg -target "/"
require 'rubygems' if RUBY_VERSION < "1.9"
require 'sinatra/base'
require 'Haml'
require 'chef'
require './chefhelper.rb'
class OpsTool < Sinatra::Base
def nodes
@helper ||= ChefHelper.new
require 'rubygems' if RUBY_VERSION < "1.9"
require 'sinatra/base'
require 'Haml'
require 'chef'
require './chefhelper.rb'
class OpsTool < Sinatra::Base
@helper = ChefHelper.new
@nodes = @helper.get_nodes