Some interesting gems to consider.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# vendor/plugins/redmine_gist/init.rb | |
# | |
require 'redmine' | |
require 'open-uri' | |
Redmine::Plugin.register :redmine_gist do | |
name 'Redmine Gist embed plugin' | |
author 'Yasushi Abe <yasushi.abe@gmail.com>' | |
description 'This is a plugin for Redmine' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# via http://tagaholic.me/2009/05/29/exploring-how-to-configure-irb.html#echo | |
def irb_verbosity_toggle | |
irb_context.echo ? irb_context.echo = false : irb_context.echo = true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Base | |
def initialize args | |
update args | |
end | |
def update args | |
args.each do |k,v| | |
send "#{k}=", v if respond_to? k | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fog' | |
require 'chef/config' | |
Chef::Config.from_file('./.chef/knife.rb') | |
EC2 = Fog::Compute.new provider: 'AWS', | |
region: Chef::Config[:knife][:region], | |
aws_access_key_id: Chef::Config[:knife][:aws_access_key_id], | |
aws_secret_access_key: Chef::Config[:knife][:aws_secret_access_key] | |
servers = EC2.servers.select { |s| s.tags["Name"] =~ /ec2\-test\-/ && s.state == "running" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application "redmine" do | |
path "/opt/redmine" | |
owner "nobody" | |
group "nogroup" | |
repository "git://github.com/redmine/redmine.git" | |
revision "2.0-stable" | |
packages ["build-essential", | |
"git", | |
"postgresql-server-dev-all", | |
"libgraphicsmagick++-dev", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this in ~/chef-repo/data_bags/aws/main.rb | |
# Upload it to the Chef Server with: | |
# | |
# knife data bag item rb aws main.rb | |
# | |
# Export the two AWS values for your account. | |
{ | |
'id' => "main", | |
'aws_access_key_id' => ENV['AWS_ACCESS_KEY_ID'], |
Example of mocking out a library in Chef so you can test the provider in isolation.
If you want to test the library itself you can do more normal Ruby things.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!./bin/knife exec | |
# A knife exec script to change chef node's name, preserving all the attributes. | |
# | |
# Usage: knife exec rename-node.rb old-name new-name | |
# | |
# Script retrieves the Node object, changes its 'name' attribute, | |
# creates new Node object with updated name and rest of attributes | |
# untouched. Then it deletes old Node and Client objects from | |
# database, and logs into the server to update it: |
OlderNewer