Created
October 29, 2010 18:36
-
-
Save adamhjk/654101 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'chef' | |
require 'chef/client' | |
require 'chef/run_context' | |
Chef::Config[:solo] = true | |
Chef::Config[:log_level] = :info | |
Chef::Log.level(:info) | |
client = Chef::Client.new | |
client.run_ohai | |
client.build_node | |
run_context = Chef::RunContext.new(client.node, Chef::CookbookCollection.new(Chef::CookbookLoader.new)) | |
unless (ARGV[0] && ARGV[1]) | |
puts "#{$0} TYPE NAME (PARAM=VALUE...PARAM=VALUE)" | |
puts " TYPE = A chef resource type (package, service, etc)" | |
puts " PARAM=VALUE A param for the resource (action=create)" | |
exit 1 | |
end | |
# Build a recipe programatically, and execute it | |
recipe = Chef::Recipe.new("adhoc", "default", run_context) | |
resource_type = ARGV[0].dup | |
resource_name = ARGV[1].dup | |
resource_arguments = Hash.new | |
2.upto(ARGV.length) do |index| | |
if ARGV[index] =~ /(.+)=(.+)/ | |
resource_arguments[$1] = $2 | |
end | |
end | |
resource = recipe.send(resource_type.to_sym, resource_name) | |
resource_arguments.each do |k,v| | |
resource.send(k, v) | |
end | |
Chef::Runner.new(run_context).converge |
This file contains hidden or 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/sh | |
./chef_direct.rb git "/tmp/chef" repository=git://github.com/opscode/chef.git reference=HEAD action=sync | |
./chef_direct.rb package sudo action=upgrade | |
./chef_direct.rb remote_file "/tmp/slashdot.html" source='http://slashdot.org' mode=0644 | |
./chef_direct.rb service apache2 action=restart | |
./chef_direct.rb service mysql action=disable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
U CRAZY