devopsgroup-io / vagrant-hostmanager

:pencil: A Vagrant plugin that manages hosts files within a multi-machine environment.
Mozilla Public License 2.0
1.46k stars 148 forks source link

Defaults to 127.0.0.1 using Docker provider #257

Closed Ilhicas closed 7 months ago

Ilhicas commented 6 years ago

On Vagrant Versions : 2.0.1 | 2.0.2 | 2.0.3 With docker : Docker version 18.03.0-ce, build 0520e24 With vagrant-hostmanager: 1.8.7 OS: 16.04.1-Ubuntu Kernel: 4.13.0-37-generic Running only on docker provider , when doing

vagrant up machine-to-up

Results in /etc/hosts

## vagrant-hostmanager-start id: 3ee2758e-bdf2-4086-b999-0ecea4a973f9
 127.0.0.1  machine-to-up 
 ## vagrant-hostmanager-end
==> machine-to-up: Creating the container...
    machine-to-up:   Name: machine-to-up
    machine-to-up:  Image: e60e1ce93767
    machine-to-up: Volume: /REMOVING/PATH
    machine-to-up:   Port: 8888:80
    machine-to-up:   Port: 8889:443
    machine-to-up:   Port: 127.0.0.1:2222:22
    machine-to-up:  
    machine-to-up: Container created: 42fff232ca0b59c2
==> machine-to-up: Starting container...
==> machine-to-up: Waiting for machine to boot. This may take a few minutes...
    machine-to-up: SSH address: 127.0.0.1:2222
    machine-to-up: SSH username: vagrant
    machine-to-up: SSH auth method: password
    machine-to-up: 
    machine-to-up: Inserting generated public key within guest...
    machine-to-up: Removing insecure key from the guest if it's present...
    machine-to-up: Key inserted! Disconnecting and reconnecting using new SSH key...
==> machine-to-up: Machine booted and ready!
==> machine-to-up: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> machine-to-up: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> machine-to-up: Running provisioner: hostmanager...

This Vagrantfile has the following remapping enabled:

machine-to-up.vm.network "forwarded_port", guest: 80, host: 8888, id: "http-machine-to-up", auto_correct: true
machine-to-up.vm.network "forwarded_port", guest: 443, host: 8889, id: "https-machine-to-up", auto_correct: true

This is traversal to all other machines declared in this Vagrantfile

This same setup was working previously.

It's not working since update from vagrant 1.91 that was causing me other non-related issues, have also worked to my knowledge under 2.0.1 version, but have since updated to 2.0.2 (by OS update), and since it's not working.

Im currently running again under 2.0.1 without luck

Have also used version 2.0.3 without luck.

Expected to have the following /etc/hosts

## vagrant-hostmanager-start id: 3ee2758e-bdf2-4086-b999-0ecea4a973f9
172.17.0.2 machine-to-up
## vagrant-hostmanager-end

The same issue is visible inside the guest container /etc/hosts resolving to 127.0.0.1

Ilhicas commented 6 years ago

Would just like to add that the issue above doesn't happen on a Jenkins slave with the following characteristics:

Vagrant 1.9.1 vagrant-hostmanager (1.8.7) Docker version 18.03.0-ce, build 0520e24 Ubuntu : 16.04 Kernel: 4.13.0-1012-azure

Ilhicas commented 6 years ago

This is a confirmed 2.+ issue Reverted to version 1.9.1 local machine and its working as expected. All other versions referred remain the same.

yeroc commented 6 years ago

Is there any known workaround for this? I'm seeing this now since upgrading to Vagrant v2.1.1.

Ilhicas commented 6 years ago

Last time I've dealt with the issue, no, the workaround was to revert vagrant version.

meshy commented 6 years ago

I'm on vagrant 2.1.1, and I'm seeing this on the VirtualBox provider.

nqb commented 6 years ago

Same issue with 1.8.9 and vagrant 2.1.2

nqb commented 6 years ago

Any updates ?

Ilhicas commented 6 years ago

I don't think there will be any updates, unless someone inherits this repo, and keeps it alive, I don't have the time to create a Pull Request, that wouldn't be seen by the repo owners anyway.

A suggestion I would give you would be to add a Docker machine without SSH that grants you changes to the hostmanager.

An example project in docker that I use alongside molecule, as vagrant and docker for me are coming to an end, its just too painful to keep vagrant with docker. You could add a vm with docker provider with box nil and no ssh and add it to your stack. https://github.com/iamluc/docker-hostmanager

schrej commented 3 years ago

Here's a beatiful hack:

config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
  if vm.provider_name == :docker
    id = vm.provider.to_s.split[1][1..-2]
      if id != "ne" # aka. we have a valid id
        nwInfo = vm.provider.driver.inspect_container(id)["NetworkSettings"]
        nwInfo["IPAddress"]
      end
    end
  end
Ilhicas commented 7 months ago

Closing given this has been open for a long time without any updates