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

Fix incorrectly named file for Windows support #229

Closed
wants to merge 1 commit into from

Conversation

pearcec
Copy link

@pearcec pearcec commented Mar 10, 2017

@BadgerOps
Copy link
Contributor

Just ran into this issue as well:

==> windows: Updating /etc/hosts file on active guest machines...
The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mv -force /tmp/hosts/hosts.windows C:\Windows\System32\drivers\etc\hosts

Stdout from the command:



Stderr from the command:

Cannot find path 'C:\tmp\hosts\hosts.windows' because it does not exist.
At line:1 char:1
+ mv -force /tmp/hosts/hosts.windows C:\Windows\System32\drivers\etc\hosts
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\tmp\hosts\hosts.windows:String) [Move-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.MoveItemCommand

Double checked c:\tmp and the file is indeed 'hosts' (Screenshot attached)
screen shot 2017-04-23 at 10 49 30 pm

@austinlparker
Copy link
Contributor

This is impacting us as well. @seth-reeser can this be merged and released?

@seth-reeser
Copy link
Member

Can everyone please provide a snippet from their Vagrant files as to how you're defining your machines? Providing that you use the syntax below this is a non-issue:

Vagrant.configure("2") do |config|
  config.vm.define "windows_server-2012r2-standard-amd64-nocm" do |config|
    ...
  end
end

@BadgerOps
Copy link
Contributor

BadgerOps commented May 3, 2017

Here's ours @seth-reeser
edit: fixed indent

Vagrant.configure('2') do |config|
  if Vagrant.has_plugin?("vagrant-cachier")
    config.cache.scope = :box
  end
  if Vagrant.has_plugin?("vagrant-hostmanager")
  config.hostmanager.enabled = true
  config.hostmanager.manage_host = false
  config.hostmanager.manage_guest = true
  config.hostmanager.ignore_private_ip = false
  config.hostmanager.include_offline = true
  end
  config.vm.define 'windows', autostart: false do |windows|
      windows.vm.provider "virtualbox" do |v|
        v.linked_clone = true
      end
      windows.vm.box = WINDOWS_BOX
      windows.vm.hostname = 'windows'
      windows.vm.communicator = 'winrm'
      windows.winrm.username = 'Administrator'
      windows.winrm.password = 'vagrant'
      windows.vm.network 'private_network', ip: '192.168.50.6'
      windows.vm.network 'forwarded_port', host: 33389, guest: 3389
      windows.vm.provision :salt do |salt|
        salt.minion_config = 'config/minion'
        salt.minion_key = 'config/key/windows.pem'
        salt.minion_pub = 'config/key/windows.pub'
        salt.masterless = false
        salt.run_highstate = true
        salt.version = SALT_VERSION
      end
    end
  end

@seth-reeser
Copy link
Member

@BadgerOps, what version of Vagrant and vagrant-hostmanager are you running?

@BadgerOps
Copy link
Contributor

BadgerOps commented May 3, 2017

Variks:~ badger$ vagrant --version
Vagrant 1.9.3
Variks:~ badger$ vagrant plugin list
vagrant-hostmanager (1.8.5)
  - Version Constraint: > 0

@seth-reeser I'm happy to help test with anything too - just let me know what I can do to help :)

@seth-reeser
Copy link
Member

@BadgerOps what should be happening is a hosts file be created in a c:\tmp\hosts directory with a file name of hosts.#{machine.name}. Try deleting that hosts file in c:\tmp and try again. In order for the true c:\drivers\etc\hosts file to get updated, you'll need to remove any vagrant-hostmanager blocks, as a file comparison is performed.

@austinlparker
Copy link
Contributor

Our Vagrantfile looks like this, roughly -


  config.hostmanager.enabled = true
  config.hostmanager.manage_host = true
  config.hostmanager.manage_guest = true
  config.hostmanager.ignore_private_ip = false
  config.hostmanager.include_offline = false
  ...
  config.vm.define "boxcar-dc" do |dc|
    ...
  end
end

The error we're seeing is as follows:

mv -force /tmp/hosts/hosts.boxcar-dc C:\Windows\System32\drivers\etc\hosts

Stdout from the command:



Stderr from the command:

Cannot find path 'C:\tmp\hosts\hosts.boxcar-dc' because it does not exist.
At line:1 char:1
+ mv -force /tmp/hosts/hosts.boxcar-dc C:\Windows\System32\drivers\etc\hosts
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\tmp\hosts\hosts.boxcar-dc:String) [Move-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.MoveItemCommand

@seth-reeser
Copy link
Member

What are the operating systems of your workstations and guest virtual machines in question?

@BadgerOps
Copy link
Contributor

Hi seth - I'm re-testing now,
Host: OS X Sierra
VM1: RHEL7.3
VM2: opentable/win-2012r2-standard-amd64-nocm

@austinlparker
Copy link
Contributor

Host is either Windows 10 or MacOS Sierra, guest is opentable/win-2012r2-standard-amd64-nocm

@BadgerOps
Copy link
Contributor

BadgerOps commented May 3, 2017

ok @seth-reeser just re-tested with a fresh VM and the above Vagrant config:

The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mv -force /tmp/hosts/hosts.windows C:\Windows\System32\drivers\etc\hosts

Stdout from the command:



Stderr from the command:

Cannot find path 'C:\tmp\hosts\hosts.windows' because it does not exist.
At line:1 char:1
+ mv -force /tmp/hosts/hosts.windows C:\Windows\System32\drivers\etc\hosts
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\tmp\hosts\hosts.windows:String) [Move-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.MoveItemCommand

and c:\tmp\hosts exists - but not hosts.default or hosts.#{machine.name}

edit: re-ran 'vagrant up' with debug logging turned on, and I see the following:

DEBUG updater: file is: /Users/badger/.vagrant.d/tmp/hosts.windows
DEBUG updater: class of file is: Pathname
 INFO environment: Getting machine: saltmaster (virtualbox)
 INFO environment: Returning cached machine: saltmaster (virtualbox)
 INFO environment: Getting machine: linux-1 (virtualbox)
 INFO environment: Returning cached machine: linux-1 (virtualbox)
 INFO environment: Getting machine: windows (virtualbox)
 INFO environment: Returning cached machine: windows (virtualbox)
 INFO winrm: Uploading: /Users/badger/.vagrant.d/tmp/hosts.windows to /tmp/hosts <<< this is where we're breaking
DEBUG winrmshell: creating hash for file /tmp/hosts
DEBUG winrmshell: Running check_files.ps1

@BadgerOps
Copy link
Contributor

Ah, looks like maybe this line ?I'm not that familiar with ruby, but could it simply be missing a trailing / ?

@BadgerOps
Copy link
Contributor

BadgerOps commented May 3, 2017

Aha! got it solved @seth-reeser,

DEBUG winrmshell: Finished uploading /Users/badger/.vagrant.d/tmp/hosts.windows to /tmp/hosts/hosts.windows (1.264 KB over 1 chunks) in (0m0.77s)
DEBUG winrmshell: No remote files to extract, skipping
DEBUG winrmshell: Uploaded 1 items dirty_check: (0m1.46s) stream_files: (0m0.77s) extract: (0m0.00s)
DEBUG winrm: powershell executing:
mv -force /tmp/hosts/hosts.windows C:\Windows\System32\drivers\etc\hosts
DEBUG winrmshell: [WinRM] opening remote shell on http:https://127.0.0.1:55985/wsman

the solution was to modify the following lines:

 -            machine.communicate.upload(file.to_s, '/tmp/hosts')
 +            machine.communicate.upload(file.to_s, "/tmp/hosts.#{machine.name}")
              if windir
 -              machine.communicate.sudo("mv -force /tmp/hosts/hosts.#{machine.name} #{realhostfile}")
 +              machine.communicate.sudo("mv -force /tmp/hosts.#{machine.name} #{realhostfile}")
              else
 -              machine.communicate.sudo("cat /tmp/hosts > #{realhostfile}")
 +              machine.communicate.sudo("cat /tmp/hosts.#{machine.name} > #{realhostfile} && rm /tmp/hosts.#{machine.name}")       

I've submitted a PR with this change here unless @pearcec wants to update this one.

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

4 participants