Skip to content

Instantly share code, notes, and snippets.

@trentonstrong
Created October 14, 2011 20:00
Show Gist options
  • Save trentonstrong/1288140 to your computer and use it in GitHub Desktop.
Save trentonstrong/1288140 to your computer and use it in GitHub Desktop.
Best thing anyone ever built
require 'chef/knife'
require 'net/ssh'
require 'net/ssh/multi'
require 'readline'
SYMFONY_BIN = "/home/ubuntu/ichange.com/skylight/symfony"
def send_ssh(node, command)
knife_ssh = Chef::Knife::Ssh.new
knife_ssh.config[:identity_file] = "~/ichangekey.pem"
knife_ssh.config[:attribute] = "ec2.public_hostname"
knife_ssh.config[:ssh_user] = "ubuntu"
query = "name:#{node.name}"
knife_ssh.name_args = [query, command]
knife_ssh.run
end
search(:node, 'roles:webserver AND chef_environment:staging') do |ws|
puts "Updating #{ws.name}"
knife_ssh = Chef::Knife::Ssh.new
send_ssh(ws, "#{SYMFONY_BIN} project:disable frontend prod")
send_ssh(ws, "sudo chef-client")
send_ssh(ws, "#{SYMFONY_BIN} project:enable frontend prod")
end
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment