Created
April 3, 2013 11:53
-
-
Save rottenbytes/5300554 to your computer and use it in GitHub Desktop.
resource chef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
action "handle" do | |
validate :resourcetype, String | |
validate :resourcename, String | |
require 'chef' | |
require 'chef/client' | |
require 'chef/run_context' | |
begin | |
Chef::Config[:solo] = true | |
Chef::Config[:log_level] = :debug | |
Chef::Log.level(:debug) | |
client = Chef::Client.new | |
client.run_ohai | |
client.build_node | |
run_context = Chef::RunContext.new(client.node, Chef::CookbookCollection.new(Chef::CookbookLoader.new)) | |
recipe = Chef::Recipe.new("adhoc", "default", run_context) | |
# create the resource | |
resource = recipe.send(request[:resourcetype].to_sym, request[:resourcename]) | |
# insert action, attribute, whatever supported by your resource type | |
request[:resourceactions].each { |action| | |
action.each_pair { |k,v| | |
resource.send(k,v) | |
} | |
} | |
Log.instance.debug("Converging for resource #{request[:resourcetype]} '#{request[:resourcename]}'") | |
status=Chef::Runner.new(run_context).converge | |
reply["status"] = status | |
rescue Exception => e | |
reply.fail "#{e}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment