fgrehm/vagrant-lxc

There should be a config directive to specify the IP to SSH to on "up"

klausman opened this issue · 6 comments

Currently, the plugin runs lxc-info -iH -n <name> to find all IP addresses of a container and then tries to SSH to the first one, which may be an Ip that is not routable from the host (or is routed to the wrong place, e.g. the host itself in the example below). As an example, if Docker is installed on both the host machine and inside the container:

$ ip a sh dev docker0
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:d6:7f:6c:35 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 scope global docker0
       valid_lft forever preferred_lft forever

$ sudo lxc-info -iH -n testhost
172.17.0.1
242.1.0.12
$

Note that this can be tricky to reproduce, there can be race conditions related to the order in which IPs are configured inside the container, including (like above) IPs that are configured by applications running inside the container (as opposed to being in the Vagrantfile).

There is currently no way to tell the Vagrant LXC plugin which IP to use for SSHing into the machine (both for commands like halt and checking state on vagrant up). I think the best option would be to add a configuration directive to specify the IP to SSH to. Even trying all IPs listed by lxc-info round-robin is dangerous: depending on how the credentials work out, it may result in the wrong machine being halted.

Good idea. are you familiar enough with ruby to whip up a PR?

My knowledge of Ruby is barely enough to be 50/50 sure I read lib/vagrant-lxc/action/fetch_ip_with_lxc_info.rb right

@hsoft Any hints where this logic should go? We tried returning a configured IP from FetchIpWithLxcInfo but that didn't work.

@worxli not really, sorry, I'd have to dig into it to know.

@hsoft would you mind making a release with the new feature?

Hey Virgil, what are release plans to have this included?