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

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 3 years ago

danowar2k commented 3 years ago

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

Cause:

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 commented 3 years ago

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

danowar2k commented 3 years ago

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

danowar2k commented 3 years ago

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

$ 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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

seth-reeser commented 3 years ago

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

ChieftainY2k commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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

danowar2k commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

danowar2k commented 1 year ago

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.