message_bus_servers:
<% p('nats.machines').each do |ip| %>
- host: <%= ip %>:<%= p('nats.port') %>
  user: <%= p('nats.user') %>
  password: <%= p('nats.password') %>
<% end %>
host: <%= p('cf_mysql.broker.host') %>
routes:
- name: "broker_<%= index %>"
  port: <%= p('cf_mysql.broker.port') %>
  uris:
  - <%= p('cf_mysql.external_host') %>
  registration_interval: 10
  health_check:
    name: script
    script_path: /var/vcap/jobs/cf-mysql-broker/bin/healthcheck.sh

<%
def discover_external_ip
     networks = spec.networks.marshal_dump
     _, network = networks.find do |_name, network_spec|
       network_spec.default
     end
     if !network
       _, network = networks.first
     end
     if !network
       raise "Could not determine IP via network spec: #{networks}"
     end
     network.ip
   end

   network_ip = discover_external_ip
   if_p('cf_mysql.broker.host') do |host_ip|
     network_ip = host_ip
   end
%>

message_bus_servers:
<% p('nats.machines').each do |ip| %>
- host: <%= ip %>:<%= p('nats.port') %>
  user: <%= p('nats.user') %>
  password: <%= p('nats.password') %>
<% end %>
host: <%= network_ip %>
routes:
- name: "broker_<%= index %>"
  port: <%= p('cf_mysql.broker.port') %>
  uris:
  - <%= p('cf_mysql.external_host') %>
  registration_interval: 10
  health_check:
    name: script
    script_path: /var/vcap/jobs/cf-mysql-broker/bin/healthcheck.sh

Use auto discovered ip as default for broker
Use auto discovered ip as default for broker
