Vous créez peut-être vous même des box Vagrant pour les partager avec vos équipes de développement. Pour cela, il est possible de déposer vos box sur un serveur HTTP ou dans un dossier partagé.

La réutilisation d’une box personnalisée est très simple et se fait ainsi pour un serveur HTTP :

Vagrant.configure("2") do |config|
  config.vm.box = "mycompany/trusty32"
  config.vm.box_url = "http://www.mycompany.com/vagrant/my-box.box"
end

Sur un dossier partagé, le fichier de configuration ressemblera à ceci :

Vagrant.configure("2") do |config|
  config.vm.box = "mycompany/trusty32"
  config.vm.box_url = "file://\\\\myserver/mysharedfolder/vagrant/my-box.box"
end

Cependant, il n’est malheureusement pas rare de voir des dossiers avec des espaces. Il faut savoir que Vagrant supporte les espaces à partir de la version 1.5.2. A noter qu’il faut échapper les espaces ainsi :

  config.vm.box_url = "file://\\\\myserver/my\ shared\ folder/vagrant/my-box.box"

Si vous avez l’erreur suivante, il faut passer en version >= 1.5.2 :

C:\myproject>vagrant -v
Vagrant 1.5.1

C:\myproject>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'mycompany/trusty32' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
C:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/uri/common.rb:176:in `split': bad URI(is not URI?): file:////myserver/my shared folder/vagrant/my-box.box (URI::InvalidURIError)
        from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/uri/common.rb:211:in `parse'
        from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/uri/common.rb:747:in `parse'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builtin/box_add.rb:448:in `metadata_url?'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builtin/box_add.rb:76:in `block in call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builtin/box_add.rb:74:in `map'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builtin/box_add.rb:74:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/warden.rb:34:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builder.rb:116:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/runner.rb:69:in `block in run'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/util/busy.rb:19:in `busy'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/runner.rb:69:in `run'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builtin/handle_box.rb:75:in `handle_box'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builtin/handle_box.rb:42:in `block in call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builtin/handle_box.rb:36:in `synchronize'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builtin/handle_box.rb:36:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/warden.rb:34:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/warden.rb:34:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/warden.rb:34:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builder.rb:116:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/runner.rb:69:in `block in run'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/util/busy.rb:19:in `busy'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/runner.rb:69:in `run'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builtin/call.rb:51:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/warden.rb:34:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/plugins/providers/virtualbox/action/check_virtualbox.rb:17:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/warden.rb:34:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/builder.rb:116:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/runner.rb:69:in `block in run'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/util/busy.rb:19:in `busy'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/action/runner.rb:69:in `run'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/machine.rb:157:in `action'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.5.1/lib/vagrant/batch_action.rb:72:in `block (2 levels) in run'

De plus, l’ajout d’une box depuis un dossier partagé sous Windows ne refonctionne que depuis la version 1.6.0 de Vagrant.

Si vous avez l’erreur suivante, il faut passer en version >= 1.6.0 :

C:\myproject>vagrant -v
Vagrant 1.5.4

C:\myproject>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'mycompany/trusty32' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
You specified a network share path as a path to add a box. Vagrant current doesn't support network share URLs. Please copy the file
from the network share to your local machine, then add it from there.

URL: //myserver/my shared folder/vagrant/my-box.box

Vous pouvez donc maintenant créer vos propres box et les partager sans souci en évitant la phase de téléchargement sur Internet et un provisionning (un peu trop long).