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 146 forks source link

plugin is broken on Vagrant 2.2.13 #280

Closed tmoschou closed 3 years ago

tmoschou commented 4 years ago

The plugin does not modify the guest or host /etc/hosts file on the latest version.

$ vagrant --version
Vagrant 2.2.13
$ vagrant plugin list
vagrant-hostmanager (1.8.9, global)

Vagrant file:

Vagrant.configure("2") do |config|

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

  config.vm.box = "ubuntu/focal64"

  config.vm.provider "virtualbox" do |v|
    v.memory = 1024
    v.cpus = 1
  end

  config.vm.define "node-1" do |node|
    node.vm.hostname = "node-1.local"
    node.vm.network "private_network", ip: "192.168.99.101", hostname: true
  end

  config.vm.define "node-2" do |node|
    node.vm.hostname = "node-2.local"
    node.vm.network "private_network", ip: "192.168.99.102", hostname: true
  end

end
$ vagrant up
Bringing machine 'node-1' up with 'virtualbox' provider...
Bringing machine 'node-2' up with 'virtualbox' provider...
==> node-1: Importing base box 'ubuntu/focal64'...
==> node-1: Matching MAC address for NAT networking...
==> node-1: Checking if box 'ubuntu/focal64' version '20201105.0.0' is up to date...
==> node-1: Setting the name of the VM: test_node-1_1605746445848_50004
==> node-1: Clearing any previously set network interfaces...
==> node-1: Preparing network interfaces based on configuration...
    node-1: Adapter 1: nat
    node-1: Adapter 2: hostonly
==> node-1: Forwarding ports...
    node-1: 22 (guest) => 2222 (host) (adapter 1)
==> node-1: Running 'pre-boot' VM customizations...
==> node-1: Booting VM...
==> node-1: Waiting for machine to boot. This may take a few minutes...
    node-1: SSH address: 127.0.0.1:2222
    node-1: SSH username: vagrant
    node-1: SSH auth method: private key
    node-1: Warning: Connection reset. Retrying...
    node-1: Warning: Remote connection disconnect. Retrying...
    node-1:
    node-1: Vagrant insecure key detected. Vagrant will automatically replace
    node-1: this with a newly generated keypair for better security.
    node-1:
    node-1: Inserting generated public key within guest...
    node-1: Removing insecure key from the guest if it's present...
    node-1: Key inserted! Disconnecting and reconnecting using new SSH key...
==> node-1: Machine booted and ready!
==> node-1: Checking for guest additions in VM...
==> node-1: Setting hostname...
==> node-1: Configuring and enabling network interfaces...
==> node-1: Mounting shared folders...
    node-1: /vagrant => /REDACTED/test
==> node-2: Importing base box 'ubuntu/focal64'...
==> node-2: Matching MAC address for NAT networking...
==> node-2: Checking if box 'ubuntu/focal64' version '20201105.0.0' is up to date...
==> node-2: Setting the name of the VM: test_node-2_1605746482555_65870
==> node-2: Fixed port collision for 22 => 2222. Now on port 2200.
==> node-2: Clearing any previously set network interfaces...
==> node-2: Preparing network interfaces based on configuration...
    node-2: Adapter 1: nat
    node-2: Adapter 2: hostonly
==> node-2: Forwarding ports...
    node-2: 22 (guest) => 2200 (host) (adapter 1)
==> node-2: Running 'pre-boot' VM customizations...
==> node-2: Booting VM...
==> node-2: Waiting for machine to boot. This may take a few minutes...
    node-2: SSH address: 127.0.0.1:2200
    node-2: SSH username: vagrant
    node-2: SSH auth method: private key
    node-2: Warning: Connection reset. Retrying...
    node-2: Warning: Remote connection disconnect. Retrying...
    node-2:
    node-2: Vagrant insecure key detected. Vagrant will automatically replace
    node-2: this with a newly generated keypair for better security.
    node-2:
    node-2: Inserting generated public key within guest...
    node-2: Removing insecure key from the guest if it's present...
    node-2: Key inserted! Disconnecting and reconnecting using new SSH key...
==> node-2: Machine booted and ready!
==> node-2: Checking for guest additions in VM...
==> node-2: Setting hostname...
==> node-2: Configuring and enabling network interfaces...
==> node-2: Mounting shared folders...
    node-2: /vagrant => /REDACTED/test```
$ cat .vagrant/bundler/global.sol
{"dependencies":[["vagrant-hostmanager",["= 1.8.9"]]],"checksum":"542547089d98abef9194b989e357b659e4e7d49b618219ad1efbcf14c018ca90","vagrant_version":"2.2.13"}

No entries are modified on the host's (macOS) /etc/hosts. Likewise for the guests:

$ vagrant ssh node-1
vagrant@node-1:~$ cat /etc/hosts
192.168.99.101  node-1.local    node-1
127.0.0.1   localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost   ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
127.0.1.1   ubuntu-focal    ubuntu-focal

The first line is managed by vagrant itself through he hostname: true option to node.vm.network. Normally there would be an entry for node-2 in a block managed by the plugin at the end.

tmoschou commented 4 years ago

Oddly I can see that the plugin does get called on vagrant destroy, just not vagrant up

$ vagrant destroy
    node-2: Are you sure you want to destroy the 'node-2' VM? [y/N] y
==> node-2: Forcing shutdown of VM...
==> node-2: Destroying VM and associated drives...
==> node-2: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> node-2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
Password:
    node-1: Are you sure you want to destroy the 'node-1' VM? [y/N] y
==> node-1: Forcing shutdown of VM...
==> node-1: Destroying VM and associated drives...
==> node-1: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> node-1: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
tmoschou commented 4 years ago

Looks like a regression in vagrant

https://github.com/hashicorp/vagrant/issues/12035

should be resolved in vagrant 2.2.14

seth-reeser commented 4 years ago

Hi @tmoschou, thanks for digging into this - we'll await the 2.2.14 release.

ninjabreakbot commented 4 years ago

Running 2.2.14, I am experiencing an update to the vagrant box hosts file, but not the hosts. Can anyone else confirm this was resolved for them in 2.2.14?

jmack707 commented 3 years ago

Problem appears to be fixed in 2.2.14.

Vagrant.configure("2") do |config|

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

  config.vm.define "master" do |master|
    master.vm.box = "centos/7"
    master.vm.hostname = "master.home.test"
    master.vm.synced_folder  ".", "/vagrant", disabled: true
    master.vm.network :private_network, ip: "10.1.20.60", hostname: true
    master.hostmanager.aliases = %w(master.home.test master)
[vagrant@master ~]$ cat /etc/hosts
10.1.20.60      master.home.test      master
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6