sous-chefs/vagrant

Plugins install on wrong PATH when VAGRANT_HOME is set to another location than homedir

nicutor opened this issue · 2 comments

Hi,

I've set a different VAGRANT_HOME to "D:\WORK\.vagrant.d" (for example), but, when I am using the vagrant_plugin resource, everything is still installed on C:\Users#{username}\.vagrant.d

Please modify the following code to not overwrite the PATH if VAGRANT_HOME is already set and is different than homedir/.vagrant.d

    def vagrant_home
      user_home_dir = home_dir
      ::File.join(user_home_dir, '.vagrant.d') unless user_home_dir.nil?
    end

    def home_dir
      return Dir.home unless username

      # Dir.home(user) raises ArgumentError: user `user` doesn't exist
      # on Windows so we must workaround for now.
      if windows?
        "C:/Users/#{username}" if Dir.exist?("C:/Users/#{username}")
      else
        begin
          Dir.home(username)
        rescue ArgumentError
          raise UserNotFoundError
        end
      end
    end

I just got bit by this today. I've tested that adjusting the method to the below works but ends up pulling the variable from the user executing Chef which may not be the same as the user defined at node['vagrant']['user']. In my particular use case this is ok because I'll be running sudo -E chef-solo on a workstation with node['vagrant']['user'] set to the same user.

def vagrant_home
  user_home_dir = home_dir
  ENV['VAGRANT_HOME'] || ::File.join(user_home_dir, '.vagrant.d') unless user_home_dir.nil?
end

@jtimberman @cheeseplus any objections to this fix?

I've also noticed that the plugins always have root for group ownership. Will need another issue opened for that...

lock commented

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.