Cornelia Davis
Cornelia Davis

Reputation: 221

How can I access the IP address of the server for a BOSH deployed job?

Many of the jobs in the standard cloud foundry release have templates that leverage Ruby erb to insert values from the bosh deployment manifest into the files that become part of the installed component. For example, the template for the postgresql gateway startup script includes lines such as the following:

PG_ADMIN_USER=<%= properties.postgresql_gateway.admin_user || "pg_admin" %>
PG_ADMIN_GROUP=<%= properties.postgresql_gateway.admin_group || "admin" %>
PG_ADMIN_PASSWD_HASH=<%= properties.postgresql_gateway.admin_passwd_hash || "" %>

which replaces will instantiate the file as follows:

PG_ADMIN_USER=adminadmin
PG_ADMIN_GROUP=admin
PG_ADMIN_PASSWD_HASH=

if your bosh release manifest has the following in it.

properties:
  postgresql_gateway:
    check_orphan_interval: 7200
    token: AAAeAh4BXFBXwLrrWJCpQTfeDnaCn7m
    supported_versions: ["9.0"]
    version_aliases:
      current: "9.0"
    admin_user: adminadmin
    admin_group: admin

Is there a way for me to dynamically insert IP address of a VM?

Upvotes: 1

Views: 935

Answers (1)

Cornelia Davis
Cornelia Davis

Reputation: 221

Yes. There is another object available in the context in which these template expressions are evaluated - the "spec" object. I'll leave it up to you to dig through and see what all is available in the spec object, but one of the most useful bits I've found to date was the part that gives the IP address of the server this template is being instantiated on. You can see an example of this in the mods I describe in the exercise we went through deploying the sample echo service via BOSH:

exec java \
    -jar EchoServer-0.1.0.jar \
    -ipaddress <%= spec.networks.default.ip %> \
    -port <%= properties.echoserver && properties.echoserver.port || 8080 %> \
    >>$LOG_DIR/echoserver.stdout.log \
    2>>$LOG_DIR/echoserver.stderr.log

It's the spec.networks.default.ip value that you are looking for.

Upvotes: 3

Related Questions