Created
October 5, 2011 10:22
-
-
Save iafonov/1264116 to your computer and use it in GitHub Desktop.
Deployment with 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
require 'script/util/deployer.rb' | |
abort("usage: knife exec script/deploy QUERY") unless ARGV[2] | |
Deployer.new(ARGV[2]).deploy | |
exit 0 |
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 'script/util/ssh_wrapper.rb' | |
class Deployer | |
def initialize(query_str) | |
query = Chef::Search::Query.new | |
@nodes = query.search(:node, query_str)[0] | |
@ssh = SshWrapper.new | |
@ssh.configure_session(@nodes) | |
end | |
def deploy | |
set_action_and_update_nodes('deploy') | |
end | |
def rollback | |
set_action_and_update_nodes('rollback') | |
end | |
private | |
def set_action_and_update_nodes(action) | |
@nodes.each do |node| | |
node.set['groupinator']["deploy_action"] = action | |
node.save | |
end | |
@ssh.ssh_command("sudo chef-client") | |
end | |
end |
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 'script/util/deployer.rb' | |
abort("usage: knife exec script/rollback QUERY") unless ARGV[2] | |
Deployer.new(ARGV[2]).rollback | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment