Skip to content

Instantly share code, notes, and snippets.

@griggheo
Forked from adamhjk/chef_direct.rb
Created October 29, 2010 18:37
Show Gist options
  • Save griggheo/654102 to your computer and use it in GitHub Desktop.
Save griggheo/654102 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))
# Use resources directly
Chef::Resource::Execute.new("echo foo", run_context).run_action(:run)
# Build a recipe programatically, and execute it
recipe = Chef::Recipe.new("adhoc", "default", run_context)
recipe.execute "echo bar"
recipe.package "mysql" do
action :uninstall
end
Chef::Runner.new(run_context).converge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment