Skip to content

Instantly share code, notes, and snippets.

@camelpunch
Created September 28, 2010 09:40
Show Gist options
  • Select an option

  • Save camelpunch/600714 to your computer and use it in GitHub Desktop.

Select an option

Save camelpunch/600714 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'right_aws'
require 'ruby-debug'
site = ARGV[0]
chef_32bit = 'ami-e0635694'
ec2 = RightAws::Ec2.new(ENV['AMAZON_ACCESS_KEY_ID'], ENV['AMAZON_SECRET_ACCESS_KEY'])
instances = ec2.run_instances(chef_32bit,
min = 1,
max = 1,
groups = ['default'],
key = 'camelpunch',
user_data = File.read("/Users/andrew/dev/chef-repo/roles/#{site}-data.json"),
"public",
"m1.small",
kernel = nil,
ramdisk = nil,
zone = "eu-west-1b",
monitoring = nil,
subnet_id = nil,
disable_api_termination = nil,
instance_initiated_shutdown_behaviour = nil,
block_device_mappings = [
{
:device_name => '/dev/sda1',
:ebs_delete_on_termination => false,
}
])
instance_id = instances.first[:aws_instance_id]
dns_name = ''
while dns_name.empty?
instances = ec2.describe_instances(instance_id)
dns_name = instances.first[:dns_name]
end
sleepytime = 17
puts "sleeping #{sleepytime} seconds"
sleep sleepytime
success = false
while success == false
success = system("ssh ubuntu@#{dns_name} echo 'Server is up!'")
sleep 1
end
exec "ssh ubuntu@#{dns_name} 'tail -f /var/log/chef/client.log'"
@camelpunch
Copy link
Author

This is a replacement for knife ec2 server create, as it never seems to work properly. It does things differently, and assumes that your AMI has the chef client ready to go and accept instance data.

Follow the Opscode instructions to get such an AMI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment