Created
April 3, 2012 16:49
-
-
Save cwjohnston/2293568 to your computer and use it in GitHub Desktop.
Revisions
-
cwjohnston created this gist
Apr 3, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ # knife-exec script to set git revision to be deployed for specified application # Example usage: knife exec /path/to/this/script/setrevision haystack i-fb106a9f v69.10 require 'chef/knife' require 'chef/shef/ext' # - ARGV[2] expected to be the app name (e.g. haystack, core) # - ARGV[3] expected to be the node name # - ARGV[4] expected to be the revision id abort("usage: knife exec setrevision APP NODE REVISION") unless ARGV[2] begin nodes.find(:name => ARGV[3]).each do |n| case ARGV[2] when 'haystack' n['haystack']['revision'] = ARGV[4] begin if n.save puts "Set haystack.revision to #{ARGV[4]} on node #{n['name']}." end rescue => e puts "Failed to modify node #{n['name']}: #{e.inspect}" end when 'core' n['core']['revision'] = ARGV[4] begin if n.save puts "Set core.revision to #{ARGV[4]} on node #{n['name']}." end rescue => e puts "Failed to modify node #{n['name']}: #{e.inspect}" end else puts "Did not recognize #{ARGV[2]} as a valid application." exit 1 end end rescue => e puts "Error encountered when searching for node #{ARGV[3]}: #{e.inspect}" end exit 0