On Vagrant how do I publish the IP of a node?

108 views
Skip to first unread message

Traun Leyden

unread,
Dec 15, 2014, 8:24:16 PM12/15/14
to coreo...@googlegroups.com

I'm using the "sidekick" pattern to announce the hostanme of the first node in a cluster:

ExecStart=/bin/sh -c "while true; do etcdctl set /services/couchbase/bootstrap_ip '%H\' --ttl 60;sleep 45;done"

When I run this on AWS, they have this hostname in their dns, so I'm able to connect to it directly:

$ etcdctl get /services/couchbase/bootstrap_ip
ip-10-150-73-56.ec2.internal
$ ping ip-10-150-73-56.ec2.internal
PING ip-10-150-73-56.ec2.internal (10.150.73.56) 56(84) bytes of data.
...

On Vagrant, however, it's a different story. I end up with "core-01" as the value emitted from %H in the fleetfile, and I don't know of any way to find the ip address from the hostname.

I didn't see a way in the Systemd man page to emit the ip address of the node.  I did see %m Machine ID, but didn't see a way to lookup an ip address from a Machine ID in fleetctl.

Or if there was an easy way to setup a hosts -> ip mapping in Vagrant, that would solve my problem.  I guess it could write the host->ip mapping to /etc/hosts on each machine.  

Any tips?

Christopher Armstrong

unread,
Dec 15, 2014, 8:43:41 PM12/15/14
to Traun Leyden, coreos-user
There's a Vagrant plugin to do exactly this: https://github.com/smdahlen/vagrant-hostmanager

I used this in my Ceph-on-Vagrant workshop: https://github.com/carmstrong/multinode-ceph-vagrant

--
You received this message because you are subscribed to the Google Groups "CoreOS User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coreos-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Traun Leyden

unread,
Dec 15, 2014, 8:48:39 PM12/15/14
to Christopher Armstrong, coreos-user

Rob Szumski

unread,
Dec 15, 2014, 9:05:55 PM12/15/14
to Traun Leyden, Christopher Armstrong, coreos-user
There is a hack for getting the IP, as long as you’re using Vagrant or a cloud-provider. In a systemd/fleet unit, you can include EnvironmentFile=/etc/environment and then have access to $COREOS_PUBLIC_IPV4 in that unit. Here’s a full example:

https://github.com/coreos/unit-examples/blob/master/blog-vulcan-example/mixed-register-v1.0.0-A.service#L9

This also works for AWS, Rackspace, Azure, DigitalOcean, etc. However, it does not work on bare metal. Using the vagrant plugin is probably the best way to go about this, however.

 - Rob

Traun Leyden

unread,
Dec 18, 2014, 10:32:19 AM12/18/14
to coreo...@googlegroups.com, traun....@gmail.com, ch...@opdemand.com

Thanks Rob, that's good to know.

Just as a follow up, I wasn't able to get the vagrant hostmanager working and filed an issue.

I then realized that even if I did, I still have the problem that the docker container won't have access to the /etc/hosts file, and I'd need to copy it from CoreOS into the docker container.
Reply all
Reply to author
Forward
0 new messages