Skip to content

Instantly share code, notes, and snippets.

@iafonov
Created October 5, 2011 10:22
Show Gist options
  • Save iafonov/1264116 to your computer and use it in GitHub Desktop.
Save iafonov/1264116 to your computer and use it in GitHub Desktop.
Deployment with chef
require 'script/util/deployer.rb'
abort("usage: knife exec script/deploy QUERY") unless ARGV[2]
Deployer.new(ARGV[2]).deploy
exit 0
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
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