Created
November 26, 2011 06:35
-
-
Save mattbailey/1395182 to your computer and use it in GitHub Desktop.
dnsupdater
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
# amazon-ec2 gem | |
require 'AWS' | |
# Your keys | |
ACCESS_KEY_ID = 'your AWS ID' | |
SECRET_ACCESS_KEY = 'your AWS secret' | |
# open EC2 connection | |
ec2 = AWS::EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY) | |
# drop in static hosts file for things like localhost | |
IO.foreach('hosts') {|line| puts line} | |
# Generate the rest | |
puts "\n\n# Generated by dnsupdate.rb\n" | |
ec2.describe_instances.reservationSet.item.each do |instance| | |
instance.instancesSet.item.first.tagSet.item.each do |tag| | |
if tag['key'] == 'dns' | |
# EC2 instances are tagged with 'dns' and a hostname as the value | |
# I use things like appname_railsenv_app1, etc.. | |
puts "#{instance.instancesSet.item.first.ipAddress} #{tag['value']}" | |
puts "#{instance.instancesSet.item.first.privateIpAddress} #{tag['value']}-int" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment