Skip to content

Instantly share code, notes, and snippets.

@adamhjk
Created October 29, 2010 18:36
Show Gist options
  • Save adamhjk/654101 to your computer and use it in GitHub Desktop.
Save adamhjk/654101 to your computer and use it in GitHub Desktop.
#!/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
#!/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
@adamhjk
Copy link
Author

adamhjk commented Oct 29, 2010

 
  ./chef_direct.rb package sudo action=install
   ./chef_direct.rb service apache2 action=restart
   ./chef_direct.rb git "/tmp/chef" repository=git://github.com/opscode/chef.git reference=HEAD action=sync
   ./chef_direct.rb remote_file "/tmp/slashdot.html" source='http://slashdot.org' mode=0644

@imeyer
Copy link

imeyer commented Oct 29, 2010

U CRAZY

@fujin
Copy link

fujin commented Oct 29, 2010

this is dope on a rope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment