谈谈Vagrant中的那些坑:vagrant-share引出的插件问题

Vagrant是一个基于Ruby的工具,用于创建和部署虚拟化开发环境。它 使用Oracle的开源VirtualBox虚拟化系统,使用 Chef创建自动化虚拟环境。

——引自“百度百科”

百度这句话说得够轻松。但我在使用中却遇到了若干问题,记录下来希望对自己今后有用,也对需要的人有用。本文记录第一个坑,vagrant-share引出的插件问题。

主机操作系统:Windowx 10 Pro。

一般采用VirtualBox、Git、Vagrant组合。先后安装这些组件,然后在Git命令行中来运行。具体过程不在本文讨论范围内。

第一个坑:插件vagrant-share的版本问题

在Git中运行不带任何参数的 vagrant 命令:

$ vagrant
C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- vagrant-share/helper/api (LoadError)
        from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-share-1.1.7/lib/vagrant-share/activate.rb:244:in `<encoded>'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-share-1.1.7/lib/vagrant-share/activate.rb:16:in `RGLoader_load'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-share-1.1.7/lib/vagrant-share/activate.rb:16:in `<top (required)>'
        from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-share-1.1.7/lib/vagrant-share.rb:23:in `block in <class:Plugin>'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:75:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:75:in `block (2 levels) in help'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/registry.rb:49:in `block in each'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/registry.rb:48:in `each'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/registry.rb:48:in `each'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:69:in `block in help'
        from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/optparse.rb:917:in `initialize'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:57:in `new'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:57:in `help'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:32:in `execute'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/environment.rb:308:in `cli'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/bin/vagrant:127:in `<main>'

出错了。经研究发现,错误由 vagrant-share 引发,需要安装该插件的最新版本:

$ vagrant plugin install vagrant-share --plugin-version 1.1.8
Installing the 'vagrant-share --version '1.1.8'' plugin. This can take a few minutes...
Installed the plugin 'vagrant-share (1.1.8)'!

 好了,安装了插件 vagrant-share (1.1.8)。

再次运行 vagrant命令:

$ vagrant
Usage: vagrant [options] <command> [<args>]

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

Common commands:
     box             manages boxes: installation, removal, etc.
     connect         connect to a remotely shared Vagrant environment
     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
     init            initializes a new Vagrant environment by creating a Vagrantfile
     login           log in to HashiCorp's Atlas
     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
     share           share your Vagrant environment with anyone in the world
     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
     validate        validates the Vagrantfile
     version         prints current and latest Vagrant version

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`.

 这是正常的启动状态,给出了 vagrant 命令的用法。

说到这里,可能有人会问:为什么不升级插件呢?这就是坑之所在了。我们现在来升级插件看看:

$ vagrant plugin update
Updating installed plugins...
Successfully uninstalled vagrant-share-1.1.8
Updated 'vagrant-share' to version '1.1.7'!

看见没!原来是 vagrant-share-1.1.8,升级之后变成了 vagrant-share-1.1.7。这时候再运行 vagrant 命令,那一堆错误又抛出来了。

还是重新安装一次吧(可别再用升级的了):$ vagrant plugin install vagrant-share --plugin-version 1.1.8。这是为哪般我不得而知,估计内置插件 vagrant-share 官方版本是 1.1.7,而这 1.1.8 是偏房所出,一升级当然以官方版本为主,偏房出的就被废掉了。

安装的插件来源何在呢?实际上,插件来源于 Ruby Gems:https://rubygems.org/gems

可以在页面上搜索 vagrant:

找到的插件都可以在 vagrant 中通过 vagrant plugin install <plugin name>的方式来进行安装。但正如本文所述,安装之后如果再 vagrant plugin update,则不一定有好的结果了。

posted on 2017-05-12 21:50  昭阳人  阅读(4469)  评论(0编辑  收藏  举报

导航