Vagrant failed to initialize at a very early stage ... nil:NilClass
I ran across an issue where most vagrant commands would fail, saying
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
a syntax error.
Path: <provider config: virtualbox>
Line number: 45
Message: NoMethodError: undefined method `start_with?' for nil:NilClass
Naturally, I begun investigating my local Vagrantfile, but found nothing exciting at line 45 but an array iteration whose array I knew was initialized ...
machines.each do |machine|
Eventually, I found a directory in my home directory whose name matched the box_name entry of my machines array:
:box_name => 'redacted-company-name/centos-7-oracle12c2'
Path: C:\Users\Sami.Lamti\.vagrant.d\boxes\redacted-company-name-VAGRANTSLASH-centos-7-oracle12c2\2020.02.11\virtualbox\Vagrantfile
On line 45 is this file, there was a statement who indeed could cause the above error message
if virtualbox_version.start_with?("5")
The virtualbox_version.start_with? method was defined as
def virtualbox_version()
vboxmanage = Vagrant::Util::Which.which("VBoxManage") || Vagrant::Util::Which.which("VBoxManage.exe")
if vboxmanage != nil
s = Vagrant::Util::Subprocess.execute(vboxmanage, '--version')
return s.stdout.strip!
else
return nil
end
end
Reading https://www.rubydoc.info/github/mitchellh/vagrant/Vagrant/Util/Which I learnt that Vagrant::Util::Which.which is a "Cross-platform way of finding an executable in the PATH.".
So, my issue was that VBoxManage.exe was not in my path! Adding it (C:\Program Files\Oracle\VirtualBox in my case) solved my issue and let me move on tackle the next.
I hope this will save someone else some time in the future!
Comments