vagrant-hostmanager icon indicating copy to clipboard operation
vagrant-hostmanager copied to clipboard

Update Host: Windows + git bash running vagrant leads to line ending confusion and two dozen UAC prompts while trying to change the hosts file

Open danowar2k opened this issue 3 years ago • 16 comments

#171 isn't fixed (anymore?) in 1.8.9 but maybe it's another cause, so here we go...

  • Windows 7
  • at least since Vagrant 2.2.14 - 2.2.16
  • git version 2.31.0.windows.1
  • vagrant destroy VMNAME started in git bash

Cause:

  • Pathname.read reads the Windows CRLF hosts file and transforms the CRLFs in the file into LF because it "thinks" it should be Unix line endings. This is content A.
  • The file content with LF is checked for changes, the new block with LFs is inserted using regex substitution and then the whole file content is changed from LF to CRLF using String.encode on Windows. This results in content B
  • Content A and content B is compared using !=
  • A has LF, B has CRLF, so they are not equal, so B is saved to file
  • Next time hostmanager checks, it reads the hosts file again, converts the CRLF to LF, etc. etc. etc.

This led to two dozen UAC prompts for writing to the system directory containing the hosts file.

Why that is happening now I can't say. As Ruby hasn't the reputation of having a very stable API, maybe Vagrant had an update of the embedded Ruby version (2.6.7 in Vagrant 2.2.16) and the Pathname.read function now works slightly different than before...but I only discovered the problem when I tried to destroy one of my VMs and was bombarded by UAC prompts.

danowar2k avatar May 08 '21 19:05 danowar2k

PR ready: https://github.com/devopsgroup-io/vagrant-hostmanager/pull/283/files

danowar2k avatar May 08 '21 19:05 danowar2k

Something's still not right there...I'll check...

danowar2k avatar May 10 '21 13:05 danowar2k

Okay, so I updated the PR with another commit. Now differences between files are checked at the correct spot.

This leaves me with a lot less UAC prompts, but

  • There are still two UAC prompts when destroying a VM instead of one. One of them deletes the VM hostname line from the hosts file, but the second one doesn't seem to do anything at all with the hosts file.
  • I still get the following output from vagrant destroy
$ vagrant destroy ansible-cm
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
    ansible-cm: Are you sure you want to destroy the 'ansible-cm' VM? [y/N] y
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: Forcing shutdown of VM...
==> ansible-cm: Destroying VM and associated drives...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> ansible-cm: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> ansible-cm: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...

danowar2k avatar May 10 '21 14:05 danowar2k

My Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :
# Versions to reference in code or info
Vagrant.configure("2") do |config|
  # The subnet used for this vagrant config
  ansible_network = "192.168.123"
  # The IP of the Ansible control machine VM
  cm_ip = ansible_network + ".2"
  # The hostname of the Ansible CM
  cm_name = "ansible-cm"

  # Automatically manage hosts files. Do it on the guests and the host
  # (when using Windows as a host, this requires UAC privileges)
  config.hostmanager.enabled = true
  config.hostmanager.manage_host = true
  config.hostmanager.manage_guest = true

  # Now the Ansible control machine that can be used to configure the server for applications
  config.vm.define "#{cm_name}" do |ansible_cm|
    ansible_cm.vm.hostname = cm_name
    # The chosen OS is irrelevant for our infrastructure
    # the only thing required is that Ansible can be installed without fuss
    ansible_cm.vm.box = "bento/ubuntu-20.04"
    ansible_cm.vm.network "private_network", ip: cm_ip
    # This is convenient when using SSH keys to access other servers
    ansible_cm.ssh.forward_agent = true
  end
end

My Vagrant plugins:

$ vagrant plugin list
vagrant-disksize (0.1.3, global)
vagrant-host-shell (0.0.4, global)
vagrant-hostmanager (1.8.9, global)
vagrant-registration (1.3.4, global)
vagrant-reload (0.0.1, global)
vagrant-vbguest (0.29.0, global)

danowar2k avatar May 10 '21 14:05 danowar2k

I deinstalled the other Vagrant plugins, and even with only vagrant-hostmanager installed, the above is the same. I even got 4 UAC prompts instead of 2.

danowar2k avatar May 10 '21 14:05 danowar2k

So...what can I do to help integrate the PR for the UAC part of the issue?

danowar2k avatar May 12 '21 15:05 danowar2k

Hi @danowar2k, we're reviewing this issue and your PR, stay tuned.

seth-reeser avatar May 12 '21 16:05 seth-reeser

After recent upgrade to Vagrant 2.2.18 and running plugin update I run into exactly same issue - loads and loads of the UAC prompts about the hosts file , just after vagrant destroy

OS: Win10 Pro x64 10.0.19043 Shell: Cygwin bash Vagrant: Vagrant 2.2.18

Plugins:

vagrant-disksize (0.1.3, global)
vagrant-hostmanager (1.8.9, global)
vagrant-rsync-only-changed (0.9.1, global)
vagrant-vbguest (0.30.0, global)
vagrant-winnfsd (1.4.0, global)

ChieftainY2k avatar Aug 18 '21 12:08 ChieftainY2k

Same problem for me since update to latest Virtualbox / Vagrant/ Windows 10 x64 21H1 within Hyper-V mode. Also using cygwin bash from git4windows but same with cmd / powershell

Installed Version: 2.2.18
vagrant-bindfs (1.1.8, global)
vagrant-hetznercloud (0.0.1, global)
vagrant-hostmanager (1.8.9, global)
vagrant-vbguest (0.30.0, global)

but "only" 16 times for me and it's independet if I use bindfs or not:

$ vagrant destroy virtualbox-3.2
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
    virtualbox-3.2: Are you sure you want to destroy the 'virtualbox-3.2' VM? [y/N] y
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: Forcing shutdown of VM...
==> virtualbox-3.2: Destroying VM and associated drives...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> virtualbox-3.2: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...

Reiner030 avatar Sep 14 '21 17:09 Reiner030

Just ran into the same problem of it getting stuck in a loop after running vagrant destroy:

==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
red)...
    default: Are you sure you want to destroy the 'default' VM? [y/N] Y
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be requi==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
red)...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...

Unsure if I managed to skip out of it spamming escape and ctrl+c or if it sorted itself out

Vagrant: 2.2.19 Windows: 10 20H2 vagrant-pluginmanager: 1.8.9 Powershell: 5.1.19041.1320

james-Ballyhoo avatar Jan 12 '22 13:01 james-Ballyhoo

Just ran into the same issue on Git Bash when running vagrant destroy:

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

Just clicked 'no' and it stopped the loop. Confirming that the first UAC deletes the host file entry, but all the others are looping for no reason.

## vagrant-hostmanager-start id: 2df4211a-0148-40ad-801c-881688a7f2f0
192.168.33.12   app01
192.168.33.14   mc01
192.168.33.16   rmq01
192.168.33.11   web01

Vagrant: 2.2.19 Windows 10 19044 vagrant-pluginmanager: 1.8.9 Git bash: 2.30.1.windows.1

Cruhrup avatar Jul 23 '22 14:07 Cruhrup

WhatsApp Image 2023-08-16 at 23 08 46 could anyone please come up with a solution for this?

sriram02-02 avatar Aug 16 '23 17:08 sriram02-02

WhatsApp Image 2023-08-16 at 23 08 46 could anyone please come up with a solution for this?

What does this error stacktrace have to do with this issue?

danowar2k avatar Aug 16 '23 19:08 danowar2k

WhatsApp Image 2023-08-16 at 23 08 46 could anyone please come up with a solution for this?

What does this error stacktrace have to do with this issue?

I am sorry , I am a student , I didnt understan what you said

sriram02-02 avatar Aug 17 '23 05:08 sriram02-02

could anyone please propose any solutions to fix this error? new error

sriram02-02 avatar Aug 21 '23 16:08 sriram02-02

WhatsApp Image 2023-08-16 at 23 08 46 could anyone please come up with a solution for this?

What does this error stacktrace have to do with this issue?

I am sorry , I am a student , I didnt understan what you said

Your text doesn't have anything to do with the problem described in here. Please don't put it in here.

danowar2k avatar Aug 21 '23 17:08 danowar2k