Skip to content

Instantly share code, notes, and snippets.

@tjhanley
Created October 10, 2011 02:22
Show Gist options
  • Save tjhanley/1274502 to your computer and use it in GitHub Desktop.
Save tjhanley/1274502 to your computer and use it in GitHub Desktop.
Rubber Capistrano Task to create CNAME records for app hosts
# 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
@mishrarohit
Copy link

I believe this task should run after an instance is created or deleted. Any pointers on how to run this?

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