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

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

Open
danowar2k opened this issue May 8, 2021 · 16 comments

Comments

@danowar2k
Copy link

danowar2k commented May 8, 2021

#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 added a commit to danowar2k/vagrant-hostmanager that referenced this issue May 8, 2021
- Probably an universal solution for the line ending problem: Read the file, ignore how it converted line endings and just convert it to universal newline, then work on it also using just universal newlines. Comparison of old and new content then works. Finally, just write the file using universal newlines on all systems except Windows, where we convert to CRLF
@danowar2k
Copy link
Author

@danowar2k
Copy link
Author

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

@danowar2k
Copy link
Author

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
Copy link
Author

danowar2k commented May 10, 2021

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
Copy link
Author

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
Copy link
Author

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

@seth-reeser
Copy link
Member

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

@ChieftainY2k
Copy link

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)

@Reiner030
Copy link

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)...

@james-Ballyhoo
Copy link

james-Ballyhoo commented Jan 12, 2022

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

@Cruhrup
Copy link

Cruhrup commented Jul 23, 2022

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

@sriram02-02
Copy link

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

@danowar2k
Copy link
Author

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?

@sriram02-02
Copy link

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
Copy link

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

@danowar2k
Copy link
Author

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.

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

7 participants