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

Reports "Permission denied" but /etc/hosts is updated only when "sudo vagrant up" is used, not as normal user. #212

Open
dglinder opened this issue Aug 13, 2016 · 1 comment

Comments

@dglinder
Copy link

dglinder commented Aug 13, 2016

Platform: OSX 10.11.6 (El Capitan), Vagrant 1.8.5,

I have setup my account ("dan") in the /etc/sudoers so it can modify the /etc/hosts file:

Cmnd_Alias VAGRANT_HOSTMANAGER_UPDATE = /bin/cp /Users/dan/.vagrant.d/tmp/hosts.local /etc/hosts
dan ALL=(root) NOPASSWD: VAGRANT_HOSTMANAGER_UPDATE

When I run a simple vagrant up on this Vagrantfile:

Vagrant.configure("2") do |config|
  config.hostmanager.enabled = true
  config.hostmanager.manage_host = true
  config.vm.box = "centos/6"
  config.vm.hostname = "myhost"
end

The run fails:

==> default: Updating /etc/hosts file on active guest machines...
==> default: Updating /etc/hosts file on host machine (password may be required)...
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
/opt/vagrant/embedded/lib/ruby/2.2.0/fileutils.rb:1392:in `initialize': Permission denied @ rb_sysopen - /Users/dan/.vagrant.d/tmp/hosts.local (Errno::EACCES)
           from /opt/vagrant/embedded/lib/ruby/2.2.0/fileutils.rb:1392:in `open'
           from /opt/vagrant/embedded/lib/ruby/2.2.0/fileutils.rb:1392:in `block in copy_file'
           from /opt/vagrant/embedded/lib/ruby/2.2.0/fileutils.rb:1391:in `open'
           from /opt/vagrant/embedded/lib/ruby/2.2.0/fileutils.rb:1391:in `copy_file'
           from /opt/vagrant/embedded/lib/ruby/2.2.0/fileutils.rb:485:in `copy_file'
           from /opt/vagrant/embedded/lib/ruby/2.2.0/fileutils.rb:402:in `block in cp'
           from /opt/vagrant/embedded/lib/ruby/2.2.0/fileutils.rb:1570:in `block in fu_each_src_dest'
           from /opt/vagrant/embedded/lib/ruby/2.2.0/fileutils.rb:1586:in `fu_each_src_dest0'
           from /opt/vagrant/embedded/lib/ruby/2.2.0/fileutils.rb:1568:in `fu_each_src_dest'
           from /opt/vagrant/embedded/lib/ruby/2.2.0/fileutils.rb:401:in `cp'
           from /Users/dan/.vagrant.d/gems/gems/vagrant-hostmanager-1.8.5/lib/vagrant-hostmanager/hosts_file/updater.rb:68:in `update_host'
           from /Users/dan/.vagrant.d/gems/gems/vagrant-hostmanager-1.8.5/lib/vagrant-hostmanager/action/update_all.rb:46:in `call'
           from /opt/vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/action/warden.rb:34:in `call'
...much more output deleted...
        from /opt/vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/environment.rb:561:in `lock'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/machine.rb:186:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/machine.rb:186:in `action'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/batch_action.rb:82:in `block (2 levels) in run'

If I manually run sudo /bin/cp /Users/dan/.vagrant.d/tmp/hosts.local /etc/hosts as my dan user the /etc/hosts file is updated from the generated hosts.local.

@dglinder dglinder changed the title Reports "Permission denied" but /etc/hosts is updated. Reports "Permission denied" but /etc/hosts is updated only when "sudo vagrant up" is used, not as normal user. Aug 13, 2016
@ghost
Copy link

ghost commented Jan 6, 2017

In my case on Windows 10 i was looking in error that was in cmder. there was permission denied for C:/Users/Alex/.vagrant.d/tmp/hosts.local, i checked with ls -all C:/Users/Alex/.vagrant.d/tmp there was two files:
-r--r--r-- 1 Alex 0 3466 2017-01-06 10:59 hosts.local
-rw-rw-rw- 1 Alex 0 2220 2017-01-06 11:31 hosts.youwe-vm
i removed falg "Read Only" for hosts.local it solved my issue

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

1 participant