Created
November 18, 2011 00:02
-
-
Save grantr/1375042 to your computer and use it in GitHub Desktop.
set node attribute status:UP when a chef run succeeds
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
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