没有不值得去解决的问题,也没有不值得去学习的技术!

Resolve Vagrant Error: Vagrant Failed to Initialize at a Very Early Stage on Windows 10

Running vagrant on Windows 10 throws the error: Vagrant failed to initialize at a very early stage

1. Running vagrant on Windows 10 throws the error: Vagrant failed to initialize at a very early stage, as shown in Figure 1.

Running vagrant on Windows 10 throws the error: Vagrant failed to initialize at a very early stage
Figure 1
Plaintext

PS E:\wwwroot\channel-pub-api> vagrant
Vagrant failed to initialize at a very early stage:

The plugins failed to initialize correctly. This may be due to manual
modifications made within the Vagrant home directory. Vagrant can
attempt to automatically correct this issue by running:

  vagrant plugin repair

If Vagrant was recently updated, this error may be due to incompatible
versions of dependencies. To fix this problem please remove and re-install
all plugins. Vagrant can attempt to do this automatically by running:

  vagrant plugin expunge --reinstall

Or you may want to try updating the installed plugins to their latest
versions:

  vagrant plugin update

Error message given during initialization: Unable to resolve dependency: user requested 'vagrant-vbguest (= 0.15.1)'

2. The cause is likely the recent Vagrant update. Vagrant can automatically attempt to (remove and reinstall
all plugins) by running the following command; execute the command as prompted.

Plaintext

PS E:\wwwroot\channel-pub-api> vagrant plugin expunge --reinstall

This command permanently deletes all currently installed user plugins. It
should only be used when a repair command is unable to properly fix the
system.

Continue? [N]: yes

All user installed plugins have been removed from this Vagrant environment!

Vagrant will now attempt to reinstall user plugins that were removed.

3. After running the following command and switching networks, running the command in Windows PowerShell still throws the same error.

Plaintext

PS E:\wwwroot\channel-pub-api> vagrant plugin install vagrant-hostmanager
Installing the 'vagrant-hostmanager' plugin. This can take a few minutes...
Vagrant failed to load a configured plugin source. This can be caused
by a variety of issues including: transient connectivity issues, proxy
filtering rejecting access to a configured plugin source, or a configured
plugin source not responding correctly. Please review the error message
below to help resolve the issue:

  SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A (https://gems.hashicorp.com/specs.4.8.gz)

Source: https://gems.hashicorp.com/

4. Run the following command in the Windows Command Prompt; it executes successfully.

Plaintext

E:\wwwroot\channel-pub-api>vagrant plugin install vagrant-hostmanager
Installing the 'vagrant-hostmanager' plugin. This can take a few minutes...
Fetching: vagrant-hostmanager-1.8.9.gem (100%)
Installed the plugin 'vagrant-hostmanager (1.8.9)'!


5. Run vagrant again, and it throws the error:

Plaintext

E:\wwwroot\channel-pub-api>vagrant
Vagrant failed to initialize at a very early stage:

There is a syntax error in the following Vagrantfile. The syntax error
message is reproduced below for convenience:

E:/wwwroot/channel-pub-api/Vagrantfile:15: syntax error, unexpected tIDENTIFIER, expecting '}'
  weibo:    'channel-pub-api-weibo.te
       ^


6. Edit the Vagrantfile. Line 14 in the domains configuration is missing a trailing comma; add it, as shown in Figure 2.

Edit the Vagrantfile. Line 14 in the domains configuration is missing a trailing comma; add it
Figure 2
Plaintext

domains = {
  frontend: 'channel-pub-api-frontend.test',
  backend:  'channel-pub-api-backend.test',
  api:      'channel-pub-api-api.test',
  qq:       'channel-pub-api-qq.test',
  rpc:      'channel-pub-api-rpc.test'
  weibo:    'channel-pub-api-weibo.test',
  wx:       'channel-pub-api-wx.test'
}

Plaintext

domains = {
  frontend: 'channel-pub-api-frontend.test',
  backend:  'channel-pub-api-backend.test',
  api:      'channel-pub-api-api.test',
  qq:       'channel-pub-api-qq.test',
  rpc:      'channel-pub-api-rpc.test',
  weibo:    'channel-pub-api-weibo.test',
  wx:       'channel-pub-api-wx.test'
}

7. Run vagrant again, and it works normally.

Plaintext

PS E:\wwwroot\channel-pub-api> vagrant up
Vagrant failed to initialize at a very early stage:

There is a syntax error in the following Vagrantfile. The syntax error
message is reproduced below for convenience:

E:/wwwroot/channel-pub-api/Vagrantfile:15: syntax error, unexpected tIDENTIFIER, expecting '}'
  weibo:    'channel-pub-api-weibo.te
       ^
PS E:\wwwroot\channel-pub-api> vagrant up
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Fetching: micromachine-2.0.0.gem (100%)
Fetching: vagrant-vbguest-0.16.0.gem (100%)
Installed the plugin 'vagrant-vbguest (0.16.0)'!
PS E:\wwwroot\channel-pub-api> vagrant
Usage: vagrant [options]  []

    -v, --version                    Print the version and exit.
    -h, --help                       Print this help.

Common commands:
     box             manages boxes: installation, removal, etc.
     cloud           manages everything related to Vagrant Cloud
     destroy         stops and deletes all traces of the vagrant machine
     global-status   outputs status Vagrant environments for this user
     halt            stops the vagrant machine
     help            shows the help for a subcommand
     hostmanager     plugin: vagrant-hostmanager: manages the /etc/hosts file within a multi-machine environment
     init            initializes a new Vagrant environment by creating a Vagrantfile
     login
     package         packages a running vagrant environment into a box
     plugin          manages plugins: install, uninstall, update, etc.
     port            displays information about guest port mappings
     powershell      connects to machine via powershell remoting
     provision       provisions the vagrant machine
     push            deploys code in this environment to a configured destination
     rdp             connects to machine via RDP
     reload          restarts vagrant machine, loads new Vagrantfile configuration
     resume          resume a suspended vagrant machine
     snapshot        manages snapshots: saving, restoring, etc.
     ssh             connects to machine via SSH
     ssh-config      outputs OpenSSH valid configuration to connect to the machine
     status          outputs status of the vagrant machine
     suspend         suspends the machine
     up              starts and provisions the vagrant environment
     upload          upload to machine via communicator
     validate        validates the Vagrantfile
     vbguest         plugin: vagrant-vbguest: install VirtualBox Guest Additions to the machine
     version         prints current and latest Vagrant version
     winrm           executes commands on a machine via WinRM
     winrm-config    outputs WinRM configuration to connect to the machine

For help on any individual command run `vagrant COMMAND -h`

Additional subcommands are available, but are either more advanced
or not commonly used. To see all subcommands, run the command
`vagrant list-commands`.

8. To create a virtual machine, run the following command.

Plaintext

PS E:\wwwroot\channel-pub-api> vagrant up
==> channel-pub-api: Machine 'channel-pub-api' has a post `vagrant up` message. This is a message
==> channel-pub-api: from the creator of the Vagrantfile, and not from Vagrant itself:
==> channel-pub-api:
==> channel-pub-api: Frontend URL: http://channel-pub-api-frontend.test
==> channel-pub-api: Backend URL: http://channel-pub-api-backend.test
==> channel-pub-api: Api URL: http://channel-pub-api-api.test
==> channel-pub-api: Qq URL: http://channel-pub-api-qq.test
==> channel-pub-api: Rpc URL: http://channel-pub-api-rpc.test
==> channel-pub-api: Weibo URL: http://channel-pub-api-weibo.test
==> channel-pub-api: Wx URL: http://channel-pub-api-wx.test

9. After waiting for it to finish, access the following URL in a browser; it works as expected.

Plaintext

192.168.83.147 channel-pub-api-frontend.test
192.168.83.147 channel-pub-api-backend.test
192.168.83.147 channel-pub-api-api.test
192.168.83.147 channel-pub-api-qq.test
192.168.83.147 channel-pub-api-rpc.test
192.168.83.147 channel-pub-api-weibo.test
192.168.83.147 channel-pub-api-wx.test

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系