-
Notifications
You must be signed in to change notification settings - Fork 479
Description
Many of the projects in this repository can optionally use the vagrant-env plugin to make configuration easier. However, in Vagrant 2.4.3 and above, the plugin doesn't work correctly. For any project that loads the plugin, vagrant
commands fail with an error message similar to the following:
Vagrant failed to initialize at a very early stage:
There was an error loading a Vagrantfile. The file being loaded
and the error message are shown below. This is usually caused by
an invalid or undefined variable.
Path: /home/username/.vagrant.d/gems/3.3.6/gems/dotenv-0.11.1/lib/dotenv.rb
Line number: 0
Message: undefined method `exists?'
This happens because the vagrant-env plugin depends on a very old version of the dotenv gem. The gem uses the File.exists?
method, which was removed in Ruby 3.2.0. Vagrant 2.4.3 and above bundle Ruby 3.3.x, which doesn't include the method. (See hashicorp/vagrant#13550.)
Fortunately, it's easy to patch the dotenv gem to make the plugin work correctly.
For Linux hosts (also works in Git Bash on Windows hosts):
find ~/.vagrant.d/gems/*/gems/dotenv-0.11.1/lib -maxdepth 1 -name 'dotenv.rb' \
-type f -exec sed -i -e 's/File.exists?/File.exist?/g' {} \;
For Windows hosts (works with both Windows PowerShell 5.1 and PowerShell 7):
(Get-Item -Path "~\.vagrant.d\gems\*\gems\dotenv-0.11.1\lib\dotenv.rb").ForEach( {
(Get-Content -Path $PSItem -Raw).Replace('File.exists?', 'File.exist?') | `
Set-Content -Path $PSItem
} )
The vagrant-env plugin hasn't been updated since December 2015, so it seems unlikely that it will be modified to use a newer version of the gem.
I don't know the best way to address this, and it's not my decision. Possibilities include:
-
Do nothing. The problem hasn't been reported as an issue in this repository, so it may not be affecting many people (or those affected have implemented the workaround).
-
Document the workaround in the top-level
README
. -
Use a different plugin with similar functionality. For example, the vagrant-readenv plugin is a fork of vagrant-env that uses a newer version of the dotenv gem.
(I've tested the vagrant-readenv plugin, and it seems to work well. It requires only one code change in the
Vagrantfile
(if Vagrant.has_plugin?("vagrant-readenv")
).) -
Switch to a different configuration method.
What are your thoughts?