Skip to content

Instantly share code, notes, and snippets.

@adamhjk
Created October 29, 2010 18:17
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save adamhjk/654054 to your computer and use it in GitHub Desktop.
Save adamhjk/654054 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