Skip to content

Instantly share code, notes, and snippets.

@zzondlo
zzondlo / version_set.rb
Created April 4, 2012 04:38 — forked from scottsbaldwin/version_set.rb
knife plugin to set data bag attribute
# This knife plugin provides the capability to set an attribute
# value in a data bag item. By default the 'versions' data bag
# is used, but that can be overridden with the -b option.
# Copy this file to ~/.chef/plugins/knife to install the plugin.
module KnifePlugins
class DataBagVersionSet < Chef::Knife
deps do
require 'chef/data_bag'
end
@zzondlo
zzondlo / nagios_lwrp_mock.rb
Created April 3, 2012 01:30 — forked from benjaminws/nagios_lwrp_mock.rb
Mock up of nagios LWRP
nagios_command "generic_queue_size" do
command "/path/to/check_rabbitmq_queue_size.pl"
arg_one {"queue_name" => String}
arg_two {"warning_size" => Integer}
arg_three {"critical_size" => Integer}
end
nagios_service "generic_queue_size" do
nagios_command_generic_queue_size do
queue_name "random_queue"
define :sudo_user, :username => nil do
begin
r = resource(:template => "/etc/sudoers")
rescue
r = template "/etc/sudoers" do
source "sudoers.erb"
attributes { :users => [], :groups => [] }
end
end
@zzondlo
zzondlo / etc_service.rb
Created April 3, 2012 01:10 — forked from tow/etc_service.rb
chef resource for a service running in /etc/service
define :etc_service, :action => :restart do
package "daemontools" do
action :install
end
path = params[:path] ? params[:path] : ("/etc/service/" + params[:name])
log_path = params[:log_path] ? params[:log_path] : ("/var/log/multilog/" + params[:name])
if params[:action] == :delete
directory path do
action :delete
recursive :true
@zzondlo
zzondlo / gist:2288462
Created April 3, 2012 01:01 — forked from jtimberman/gist:1051513
use run context in a recipe
ruby_block "config file" do
block do
run_context = Chef::RunContext.new(node, {})
r = Chef::Resource::File.new("#{node[:wordpress][:dir]}/wp-config.php", run_context)
r.content(IO.read("#{node[:wordpress][:dir]}/wp-config-sample.php"))
r.owner("root")
r.group("root")
r.mode("0644")
r.run_action(:create)
end
{
"id": "my_app"
"databases": {
"production": {
"encoding": "utf8",
"adapter": "mysql",
"username": "my_app",
"database": "production",
"password": "coolpassword"
},
@zzondlo
zzondlo / base.rb
Created April 3, 2012 00:58 — forked from jtimberman/base.rb
an example roles/base.rb
name "base"
description "Baseline configuration for all systems."
run_list(
"recipe[ohai]",
"recipe[chef-client::delete_validation]",
"recipe[chef-client]",
"recipe[zsh]",
"recipe[git]",
"recipe[users]",
unless ARGV[0] && ARGV[1]
puts "Usage: set_password.rb username password"
exit 1
end
require 'chef'
require 'chef/config'
require 'chef/webui_user'
Chef::Config.from_file(File.expand_path("~/.chef/knife.rb"))
@zzondlo
zzondlo / Gemfile
Created March 31, 2012 21:53
rake script to switch chef servers and configure knife to use them
source 'http://rubygems.org'
gem 'colored'
gem 'escape'
gem 'facets'
gem 'extensions'
gem 'quality_extensions'
gem 'rscm'
gem 'termios'
gem 'net-ssh'
{
"name": "webserver",
"default_attributes": {
"apache2": {
"listen_ports": [
"8080",
"443"
]
}
},