談談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,則不一定有好的結果了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM