Skip to content

Instantly share code, notes, and snippets.

ports = node[:apache][:listen_ports].include?("443") ? node[:apache][:listen_ports] : [node[:apache][:listen_ports], "443"].flatten
ports_conf = nil
begin
ports_conf = resources(:template => "#{node[:apache][:dir]}/ports.conf")
ports_conf.ports(ports) unless ports_conf.ports.includes?("443")
rescue Chef::Exceptions::ResourceNotFound
template "#{node[:apache][:dir]}/ports.conf" do
source "ports.conf.erb"
variables :apache_listen_ports => ports
@adamhjk
adamhjk / gist:1014841
Created June 8, 2011 17:08
keep_last_run_list.rb
# This should be in a recipe, as early in the run list as possible
begin
node.override[:previous_run_list] = JSON.parse(Chef::FileCache.load("previous_run_list"))
rescue Chef::Exceptions::FileNotFound
Chef::Log.debug("No stored run list!")
end
Chef::FileCache.store("previous_run_list", node.run_list.to_json)
# When you want to check if the last run list had the previous role...
@adamhjk
adamhjk / r.rb
Created June 7, 2011 03:51
I like to change resources
begin
r = resources(:file => "foo")
r.source "yourfile"
rescue
r = file "foo"
...
end
end
# Write it out
File.open("/tmp/foo.json", "w") { |f| f.puts node.to_json }
# Read it in
JSON.parse(IO.read("/tmp/foo.json"))
# Link to report handlers
http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers
Chef::Log.level = :debug
# your recipe
Chef::Log.level = Chef::Config[:log_level]
run_context.resource_collection.each do |r|
r.source_line =~ /cookbooks\/(.+?)\/recipes\/(.+)\.rb:.+/
cookbook_name = $1
recipe_part = $2.gsub('/', "::")
recipe_name = "#{cookbook_name}::#{recipe_part}"
if node[:isolation][:recipes].include?(recipe_name) || node[:isolation][:cookbooks].include?(cookbook_name)
Chef::Log.info("Setting #{r.to_s} to ignore failure, via the isolation cookbook")
r.ignore_failure(true)
end
execute "update_rubygems" do
notifies :restart, "service[apache2]" if node.run_list.recipes.include?("mod_passenger")
end
default[:scout][:user] = "scout"
default[:scout][:interval] = 1
#default[:scout][:group] = "scout"
#default[:scout][:version] = '5.0.3'
#default[:scout][:scout_bin] = "/usr/bin/scout"
109 set backupdir=~/.vimbackup//,/tmp//
110 set directory=~/.vimswaps//,/tmp//
module MCollective
module Agent
# An agent that uses Opscode to manage resources
# Original credit goes to R.I. Pienaar
class ChefExistingResource < RPC::Agent
metadata :name => "SimpleRPC Existing Chef Resource Agent",
:description => "Generic resource management",
:author => "Nicolas Szalay <[email protected]>",
:license => "BSD",
:version => "1.0",