Created
October 10, 2011 02:22
-
-
Save tjhanley/1274502 to your computer and use it in GitHub Desktop.
Rubber Capistrano Task to create CNAME records for app hosts
This file contains hidden or 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
# uses route53 gem https://github.com/pcorliss/ruby_route_53 | |
namespace :rubber do | |
desc "Setup Route53 for hosts" | |
task :setup_route53 do | |
require 'route53' | |
conn = Route53::Connection.new("ACCESS_KEY","SECRET_ACCESS_KEY") | |
#List Operations | |
zones = conn.get_zones #Requests list of all zones for this account | |
records = zones.first.get_records #Gets list of all records for a specific zone | |
# puts records | |
# puts records[0].type | |
cnames = [] | |
records.each do |record| | |
cnames << record.name if record.type == 'CNAME' | |
end | |
# puts cnames | |
app_servers = rubber_instances.for_role("app") | |
puts "App Servers on #{RUBBER_ENV}" | |
app_servers.each do |instance| | |
unless cnames.include?("#{instance.name}.#{instance.domain}.") | |
# puts "\t#{instance.name}.#{instance.domain}" | |
# puts instance.external_host | |
new_record = Route53::DNSRecord.new("#{instance.name}.#{instance.domain}","CNAME","120",["#{instance.external_host}"],zones.first) | |
new_record.create | |
sleep 5 | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I believe this task should run after an instance is created or deleted. Any pointers on how to run this?