This is probably in the top ten lamest hacks of my life. But I blame capistrano for not being what I want it to be.
This replaces BINDIPADDRESS in the configuration file with the IP address of eth0 on each host.
def get_ip_address (ethernet_device = "eth0")
ip_addresses = Hash.new
run("/sbin/ifconfig #{ethernet_device} | grep inet | grep -v inet6") do |ch, stream, data|
case data
when /s*inet addr:((d+.){3}d+)s+.*/
ip_addresses["#{ch[:host]}"] = $1
end
end
return ip_addresses
end
task :put_auto_install_xml, :roles => :app do
ip_addresses = get_ip_address()
auto_install =
IO.read(
File.join(File.dirname(__FILE__), "files", "#{application}", "#{application}_auto_install_#{env}.xml")
)
put(
auto_install,
"/tmp/#{application}_auto_install-#{env}-#{build}.xml",
:mode => 0644
)
run("/bin/bash") do |ch, stream, data|
ch.send_data "/bin/sed -i -e 's/BINDIPADDRESS/#{ip_addresses[ch[:host]]}/' /tmp/#{application}_auto_install-#{env}-#{build}.xmln"
ch.send_data "exitn"
end
end
