Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Created April 15, 2011 13:59
Show Gist options
  • Save jtimberman/921743 to your computer and use it in GitHub Desktop.
Save jtimberman/921743 to your computer and use it in GitHub Desktop.
# Use Chef resources in an application via solo mode.
# Could also be configured in client mode, and then use a server.
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, nil)
p = Chef::Resource::Package.new("apache2", run_context)
p.run_action("create")
s = Chef::Resource::Service.new("apache2", run_context)
s.supports(:status => true)
s.run_action(:start)
f = Chef::Resource::File.new("/etc/apache2/apache2.conf", run_context)
f.owner("root")
f.group("root")
f.mode(0644)
f.run_action(:create)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment