Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vagrant-hostmanager still doesn't check if guests are not running in multi-machine setup #207

Open
TomaszDom opened this issue Jul 18, 2016 · 2 comments

Comments

@TomaszDom
Copy link

(I'm unable to re-open #200, so I'm reporting this again, feel free to re-open #200 and close this as a duplicate)

I'm running vagrant 1.8.4 and vagrant-hostmanager 1.8.3 (applies to vagrant 1.8.1 and vagrant-hostmanager 1.8.1/1.8.2 too). This is my config:

Vagrant.configure(2) do |config|
  config.vm.network "private_network", type: "dhcp"
  config.hostmanager.manage_host = true
  config.hostmanager.include_offline = false
    config.vm.define "MACHINE-DEV-NET" do |net|
      net.vm.box = "MACHINE-DEV-NET"
      net.vm.communicator = "winrm"
      net.vm.guest = :windows
      net.windows.set_work_network = true
      net.vm.network :forwarded_port, guest: 22, host: 2223, id: "ssh", disabled: true
      net.vm.network :forwarded_port, guest: 3389, host: 33389, id: "rdp", auto_correct: true
      net.vm.box_url = "file:https:////scrubbed"
      net.hostmanager.enabled = true
      net.hostmanager.manage_guest = true
      net.hostmanager.ignore_private_ip = false
      net.hostmanager.aliases = %w(MACHINE-dev-net.local)
      net.hostmanager.ip_resolver = proc do |machine1|
        result = ""
        machine1.communicate.execute("gwmi Win32_NetworkAdapterConfiguration | Where { $_.IPAddress } | Select -Expand IPAddress | Select-Object -Skip 2 | Select-Object -First 1") do |type, data|
          result << data if type == :stdout
        end
        (ip = /(\d+\.\d+\.\d+\.\d+)/.match(result)) && ip[1]
      end
      net.vm.provider "virtualbox" do |vb1|
        vb1.gui = false
        vb1.name = "MACHINE-DEV-NET"
        vb1.cpus = 2
        vb1.memory = "4096"
      end
    end
  config.vm.define "MACHINE-DEV-PHP" do |php|
      php.vm.box = "MACHINE-DEV-PHP"
      php.ssh.insert_key = false
      php.ssh.forward_x11 = true
      php.vm.box_url = "file:https:////scrubbed"
      php.hostmanager.enabled = true
      php.hostmanager.manage_guest = true
      php.hostmanager.ignore_private_ip = false
      php.hostmanager.aliases = %w(MACHINE-dev-php.local)
      php.hostmanager.ip_resolver = proc do |machine2|
        result = ""
        machine2.communicate.execute("ifconfig eth1") do |type, data|
          result << data if type == :stdout
        end
        (ip = /inet addr:(\d+\.\d+\.\d+\.\d+)/.match(result)) && ip[1]
      end
      php.vm.provider "virtualbox" do |vb2|
        vb2.gui = false
        vb2.name = "MACHINE-DEV-PHP"
        vb2.cpus = 2
        vb2.memory = "4096"
      end    
    end
  end

Now, if I only start the PHP machine:

vagrant up MACHINE-DEV-PHP

and then try to update the hosts file on both the PHP machine and my host:

vagrant hostmanager MACHINE-DEV-PHP

this happens:

[MACHINE-DEV-PHP] Updating /etc/hosts file...
The box is not able to report an address for WinRM to connect to yet.
WinRM cannot access this Vagrant environment. Please wait for the
Vagrant environment to be running and try again.

What? Of course WinRM cannot access anything, the NET machine is not running. This stops hostmanager.manage_host = true from working.

Same thing happens if only the NET machine is running:

[MACHINE-DEV-NET] Updating /etc/hosts file...
The provider for this Vagrant-managed machine is reporting that it
is not yet ready for SSH. Depending on your provider this can carry
different meanings. Make sure your machine is created and running and
try again. Additionally, check the output of `vagrant status` to verify
that the machine is in the state that you expect. If you continue to
get this error message, please view the documentation for the provider
you're using.

If I have both machines running, everything works great:

[MACHINE-DEV-NET] Updating /etc/hosts file...
[MACHINE-DEV-PHP] Updating /etc/hosts file...
Updating /etc/hosts file on host machine (password may be required)...

Then I found out from the documentation that it doesn't matter if I set:
hostmanager.include_offline = false
because I have:
hostmanager.ignore_private_ip = false
but even changing this to:
hostmanager.ignore_private_ip = true
then trying to move it to the config section, etc. doesn't have any effect.

If I ignore private IPs and don't include offline machines, shouldn't those machines be ignored, therefore making this:

Updating /etc/hosts file on host machine (password may be required)...

actually happen and work?

Am I doing something wrong or is this a bug? It does seem like a minor quirk, but in the environment I set up, developers mostly use the PHP machine, so the hostmanager solution for automatic setup of their host machines doesn't work at all if it's the only machine running, they have to download the huge NET box, start it, then run hostmanager, then shut the NET box down and destroy it to free up resources temporairly.

(Another report here suggested to put hostmanager.enabled = true into the config section, but that breaks the whole setup, because it tries to provision both guests with updated hosts files regardless if a machine is running or even downloaded at all when using vagrant up,vagrant halt, so after many tries, this is the mostly working multi-machine setup.

I also couldn't find any single working example of a working resolver for Windows, as standard resolvers simply don't work, neither for Windows or Ubuntu, so hopefully this will be helpful to some people.)

@bowlofeggs
Copy link

This might be related to #209, but I am not sure. I reported it separately just in case it is distinct.

@rbjorklin
Copy link

rbjorklin commented Jul 21, 2016

This affects me too. Creating this post as a +1 post others can give the thumbs up to indicate that this affects them as well.

EDIT: This combination of configuration options makes the problem go away for me:

config.hostmanager.enabled = true
config.hostmanager.manage_guest = true
config.hostmanager.manage_host = false
config.hostmanager.include_offline = false
config.hostmanager.ignore_private_ip = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants