Created
November 30, 2012 17:29
-
-
Save kitplummer/4177185 to your computer and use it in GitHub Desktop.
Initialize in EC2
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
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'fog' | |
# Import EC2 credentials e.g. @aws_access_key_id and @aws_access_key_id | |
require './config.rb' | |
# Set up a connection | |
connection = Fog::Compute.new( | |
:provider => 'AWS', | |
:region => 'us-east-1', | |
:aws_access_key_id => @aws_access_key_id, | |
:aws_secret_access_key => @aws_secret_access_key ) | |
# Produce nodes for n-ids - runs sequentially | |
for id in 3..3 | |
puts "Launching Node: #{id}" | |
user_data = """puppetmaster=pm.devopstoolbox.org | |
hostname=ddf#{id}.devopstoolbox.org | |
""" | |
server = connection.servers.create( | |
:image_id => 'ami-afd05dc6', | |
:flavor_id => 't1.micro', | |
:user_data => user_data, | |
:key_name => 'ddf-demo', | |
:groups => ['ddf'], | |
:tags => {"Name" => "Automated DDF#{id}"} | |
) | |
# wait for it to be ready to do stuff | |
server.wait_for { print "."; ready? } | |
puts "\nLaunched Node:#{id}\n" | |
puts "Public IP Address: #{server.public_ip_address}" | |
puts "Private IP Address: #{server.private_ip_address}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment