Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'chef'
require 'json'
Chef::Config.from_file '.chef/knife.rb'
versions = Hash.new(0)
result = Chef::Search::Query.new.search(:node,"name:*")[0]
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise64"
@earzur
earzur / gist:2001122
Created March 8, 2012 14:05
Some problem with chef search
run_date = Time.now
ruby_block "add current date" do
block do
node[:test_last_chef_run] = run_date.to_i
node.save
end
action :create
end
@earzur
earzur / gist:1447613
Created December 8, 2011 17:01
some capistrano code to define roles and hosts from chef
def load_roles_and_hosts_from_chef(query)
Chef::Search::Query.new.search(:node,query) do |node|
node_role = node[:platform_role] || "default"
server_name = if defined? user && user && !user.empty?
"#{user}@#{node.name}"
else
node.name
end
if node_role.kind_of? Array
node_role.each do |role|
@earzur
earzur / gist:1270713
Created October 7, 2011 16:25
conditional python package installation with chef
execute "pip install yolk" do
not_if { ::File.exists?("/usr/local/bin/yolk") }
end
%w(http://www.vazor.com/media/python-cjson-1.0.6.tar.gz
mysql-python
lxml python-cjson
http://git.dbzteam.org/pyinotify/snapshot/pyinotify-0.8.6.tar.gz
pip pycrypto).each do |pkg|
@earzur
earzur / gist:934771
Created April 21, 2011 15:26
some drool rule
rule "parse host from localhost messages"
when
m : GELFMessage( host == "localhost" )
then
Matcher matcher = Pattern.compile("([\\w\\.\\-]+)|l=([A-Z_a-z]+)|").matcher(m.getShortMessage());
if (matcher.find()) {
System.out.println("host: " + matcher.group(1) + " l=" + matcher.group(2));
m.setHost(matcher.group(1));
m.addAdditionalData("_level",matcher.group(2));
}
@earzur
earzur / gist:930778
Created April 20, 2011 08:56
queues to store and back
task :queues_to_store, :roles => [:app,:master] do
logger.info "activating queues => store"
run "#{jboss_target_directory}/bin/twiddle.sh -u #{twiddle_user} -p #{twiddle_password} set RunMyProcess:service=Queues AllQueuesStore true" rescue logger.info "Twiddle Error ..."
end
task :no_queues_to_store, :roles => [:app,:master] do
logger.info "de-activating queues => store"
run "#{jboss_target_directory}/bin/twiddle.sh -u #{twiddle_user} -p #{twiddle_password} set RunMyProcess:service=Queues AllQueuesStore false" rescue logger.info "Twiddle Error ..."
end
@earzur
earzur / progress_bar.rb
Created December 23, 2010 07:33
A nifty progress bar in 1 line of ruby
i = 0; while i <= 15; print "[#{'=' * i}#{' ' * (15 - i)}] #{((i/15.0) * 100).round}%\r"; i += 1; sleep 0.2; end; puts