vagrant icon indicating copy to clipboard operation
vagrant copied to clipboard

vagrant-vbguest/hosts/virtualbox.rb typo error

Open D4d0s opened this issue 1 year ago • 18 comments

Debug output

==> default: Attempting graceful shutdown of VM...
==> default: Destroying VM and associated drives...
/usr/share/vagrant/gems/gems/vagrant-vbguest-0.32.0/lib/vagrant-vbguest/hosts/virtualbox.rb:84:in `block in guess_local_iso': undefined method `exists?' for class File (NoMethodError)

            path && File.exists?(path)
                        ^^^^^^^^

Expected behavior

Vagrant up bring up a vm

Actual behavior

vagrant fails bringing up a vm when is trying to update vbguest

Reproduction information

Vagrant version

Vagrant 2.3.7

Host operating system

opensuse tumbleweed VERSION=20240521

Guest operating system

Centos7 (a box of)

Steps to reproduce

So i fixed it by editing the file /usr/share/vagrant/gems/gems/vagrant-vbguest-0.32.0/lib/vagrant-vbguest/hosts/virtualbox.rb:

def guess_local_iso
          Array(platform_path).find do |path|
-             path && File.exists?(path)
+            path && File.exist?(path)
          end
        end

The NoMethodError give me the clue. And the ^^^^^ :-) Is easy to fix but it is annoying anyway.

Vagrantfile

# Copy-paste your Vagrantfile here. Remove any sensitive information such as passwords, authentication tokens, or email addresses.

D4d0s avatar May 30 '24 09:05 D4d0s

Please fix it.

aironi avatar Aug 22 '24 11:08 aironi

For anyone looking for a fix, see this fork: https://github.com/dheerapat/vagrant-vbguest

dangra avatar Sep 02 '24 18:09 dangra

For anyone looking for a fix, see this fork: https://github.com/dheerapat/vagrant-vbguest

Works on my machine (Ubuntu 24.04, Vagrant 2.4.2, VirtualBox 7.0.16)!

linuskmr avatar Nov 13 '24 09:11 linuskmr

I can confirm that this behavior reproduces with Vagrant 2.4.3, during a vagrant up operation, when it tries to install the Guest Additions for VirtualBox 7.0.22:

==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 6.1.18
    default: VirtualBox Version: 7.0
==> default: Attempting graceful shutdown of VM...
==> default: Destroying VM and associated drives...
C:/Users/z003txkv/.vagrant.d/gems/3.3.6/gems/vagrant-vbguest-0.32.0/lib/vagrant-vbguest/hosts/virtualbox.rb:84:in 'block in guess_local_iso': undefined method 'exists?' for class File (NoMethodError)

            path && File.exists?(path)
                        ^^^^^^^^
[...]
FATAL vagrant up failed

Guest OS is CentOS 7.

Full stack trace

rismanma1 avatar Nov 14 '24 04:11 rismanma1

rismanma1 commented 12 hours ago I can confirm that this behavior reproduces with Vagrant 2.4.3, during a vagrant up operation, when it tries to install the Guest Additions for VirtualBox 7.0.22:

I suppose this means that we cannot use Vagrant 2.4.3 or higher (and I think 2.4.2 either) with this vbguest plugin any longer, unless we edit the plugin's code (to remove the "exists" call)?

rismanma1 avatar Nov 14 '24 17:11 rismanma1

This isn't a vagrant issue this is a deprecated call that is now removed from newer ruby 3.x versions. This essentially is a bug in the plugin and since the owner has archived the repo for the plugin I don't see it getting fixed anytime soon. you'll have to either fork it and update the plugin yourself or use someone else's fork that fixed it like @dangra mentioned he created a few comments back.

Stromweld avatar Nov 14 '24 19:11 Stromweld

Just to clarify, the fork isn't mine but @dheerapat's who I don't know. I checked his fork and the commits were sane as of today.

My approach to ship the fix for my dev environment is to compile the gem and distribute it along the Vagrantfile like in:

# vagrant-vbguest plugin workaround for https://github.com/dotless-de/vagrant-vbguest/issues/332
ENV["VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT"] = "1"

Vagrant.configure('2') do |config|
  # the official vagrant-vbguest plugin was archived, it fails to run on ruby 3.2+.
  # The gem referenced here was compiled from https://github.com/dheerapat/vagrant-vbguest
  config.vagrant.plugins = {
    'vagrant-vbguest' => {
      'sources' =>[
        'vagrant-vbguest-0.32.1.gem',
        'https://rubygems.org/', # needed but not used
      ],
    }
  }
  # ... the rest of your vagrant file
end

dangra avatar Nov 14 '24 20:11 dangra

dheerapat/vagrant-vbguest works for me with:

  • Linux Mint 22 (based on Ubuntu noble)
  • Vagrant 2.4.3 (apt install, brew install is broken)
  • VirtualBox 7.0.22
  • vagrant-vbguest (0.32.1) built with Ruby 3.3.6

mlavi avatar Nov 14 '24 20:11 mlavi

Same here, dheerapat/vagrant-vbguest works with:

  • Ubuntu 24.04
  • Vagrant 2.4.3
  • VirtualBox 7.0.22
  • vagrant-vbguest (0.32.1) built with Ruby 3.2.3

To be honest I faced also https://github.com/hashicorp/vagrant/issues/13372. In my case, it was enough to disable the guest additions update config.vbguest.auto_update = false and use the ones inside the guest. Otherwise vbguest tries to update the guest additions to 7.0.22 but it hangs

Andreagit97 avatar Nov 16 '24 14:11 Andreagit97

@mlavi @Andreagit97 How did you install it? I followed the instructions in the repository, but I got this error when I run vagrant up

Vagrant failed to initialize at a very early stage:

The plugins failed to load properly. The error message given is
shown below.

cannot load such file -- vagrant/vbguest

I'm using windows and I built the gem using the binaries from vagrant folder

> & 'C:\Program Files\Vagrant\embedded\mingw64\bin\gem' build .\vagrant-vbguest.gemspec

> vagrant plugin install .\vagrant-vbguest-0.32.1.gem

salazarr-js avatar Nov 20 '24 22:11 salazarr-js

I used the instructions in the repo

gem build vagrant-vbguest.gemspec
vagrant plugin install vagrant-vbguest-0.32.1.gem

and then added this to my vagrant file as reported here: https://github.com/hashicorp/vagrant/issues/13404#issuecomment-2477303080

  config.vagrant.plugins = {
    'vagrant-vbguest' => {
      'sources' =>[
        'vagrant-vbguest-0.32.1.gem',
        'https://rubygems.org/', # needed but not used
      ],
    }
  }

Andreagit97 avatar Nov 21 '24 09:11 Andreagit97

I didn't install the fork but just modified the source file referred to by the Ruby interpreter myself and changed File.exists?(path) to File.exist?(path); works.

$ vagrant up
...
/home/USER/.vagrant.d/gems/3.3.5/gems/vagrant-vbguest-0.32.0/lib/vagrant-vbguest/hosts/virtualbox.rb:84:in `block in guess_local_iso': undefined method `exists?' for class File (NoMethodError)

            path && File.exists?(path)
                        ^^^^^^^^
Did you mean?  exist?

linuskmr avatar Nov 21 '24 10:11 linuskmr

I didn't install the fork but just modified the source file referred to by the Ruby interpreter myself and changed File.exists?(path) to File.exist?(path); works.

Since I have users who use a process I maintain which runs "vagrant up", I did the same but did so programmatically:

echo "Updating Vagrant vbguest plugin code to be compatible with Ruby 3.2.0 and later:"
for pluginDirectory in `find ~/.vagrant.d/gems/ -name 'vagrant-vbguest'`; do
        pluginFile="$pluginDirectory/hosts/virtualbox.rb"
        echo "  $pluginFile"
        test -w "$pluginFile" || error "Could not access plugin code file '$pluginFile'" 1
        sed --in-place 's/File\.exists?/File\.exist?/g' $pluginFile
done

I just had to make sure that with that process, that the above code runs after plugins are installed and updated but before we get to "vagrant up"

Also I thought it was easiest to loop over every Ruby-version directory I could find (as you probably noticed, under "gems" there's a directory named for the Ruby version) -- instead of trying to figure out the one in question. (Note that the "error" command is just a function we have defined that prints out an error message and exits the script)

rismanma1 avatar Nov 22 '24 05:11 rismanma1

please, share vagrant-vbguest-0.32.1.gem builded file somebody @mlavi

LexisDev avatar Dec 14 '24 11:12 LexisDev

@LexisDev Sorry, I shouldn't because I could give you malicious code (malware, ransomware, etc.) or perhaps I built it in some way that is specific to my environment. I recommend you don't accept someone else giving you the gem file, but reproduce the build as described above.

mlavi avatar Dec 14 '24 17:12 mlavi

I didn't install the fork but just modified the source file referred to by the Ruby interpreter myself and changed File.exists?(path) to File.exist?(path); works.

$ vagrant up
...
/home/USER/.vagrant.d/gems/3.3.5/gems/vagrant-vbguest-0.32.0/lib/vagrant-vbguest/hosts/virtualbox.rb:84:in `block in guess_local_iso': undefined method `exists?' for class File (NoMethodError)

            path && File.exists?(path)
                        ^^^^^^^^
Did you mean?  exist?

Notably, I did this little dirty trick, and it let me get to the point where I could vagrant ssh into the system... nut, I believe it may have been the cause for a downstream issue preventing me from being able to ssh and scp via 127.0.0.1. e.g. command ssh -o IdentitiesOnly=yes -i .vagrant/machines/default/virtualbox/private_key [email protected].

There is no private_key file generated and stored here any longer... thus, my required workflow (to export files from vagrant via scp) isn't actually fixed. Curious if others have had similar issues with this workaround.

mochsner avatar Dec 24 '24 15:12 mochsner

For anyone looking for a fix, see this fork: https://github.com/dheerapat/vagrant-vbguest

The fixed fork works.

I submitted a pull request to fix grammar and spelling errors in the readme.

amedee avatar Jan 30 '25 14:01 amedee

If you don't want to have to deal with modifying source or using a patched fork of vagrant-vbguest, I created a gist that can be added to the top of your Vagrantfile to monkey patch the Ruby File object to restore the deprecated File.exists? method (just calls File.exist?). https://gist.github.com/AW-Britt/4d412ec308f5890c9bd68756f13bfef4

AW-Britt avatar Jun 05 '25 06:06 AW-Britt