Skip to content

Instantly share code, notes, and snippets.

@schisamo
Created October 26, 2010 22:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schisamo/648020 to your computer and use it in GitHub Desktop.
Save schisamo/648020 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.instance_eval <<-EOH
execute "echo bar"
EOH
Chef::Runner.new(run_context).converge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment