Skip to content

Instantly share code, notes, and snippets.

@grantr
Created November 18, 2011 00:02
Show Gist options
  • Save grantr/1375042 to your computer and use it in GitHub Desktop.
Save grantr/1375042 to your computer and use it in GitHub Desktop.
set node attribute status:UP when a chef run succeeds
require "chef/handler"
class StatusAttributeHandler < Chef::Handler
VERSION = "0.0.1"
DEFAULTS = {
:attribute_name => 'status',
:success_status => 'UP'
}
def initialize(options={})
@options = DEFAULTS.merge(options)
@attribute_name = @options[:attribute_name]
@success_status = @options[:success_status]
end
def report
if run_status.success?
# if run succeeded, set the default value of the status attribute to UP
node = run_status.node
unless node.normal[@attribute_name] == @success_status
Chef::Log.info("Setting #{@attribute_name} to #{@success_status}")
run_status.node.normal[@attribute_name] = @success_status
run_status.node.save
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment