Skip to content

Instantly share code, notes, and snippets.

@dasgoll
Created April 2, 2015 07:39
Show Gist options
  • Save dasgoll/42e8bf75c1b77fcc69b8 to your computer and use it in GitHub Desktop.
Save dasgoll/42e8bf75c1b77fcc69b8 to your computer and use it in GitHub Desktop.
I found the multiple options confusing, so I decided to test all of them to see exactly what they do. I'm using VirtualBox 4.2.16-r86992 and Vagrant 1.3.3.
I created a directory called nametest and ran vagrant init precise64 http://files.vagrantup.com/precise64.box to generate a default Vagrantfile. Then I opened the VirtualBox GUI so I could see what names the boxes I create would show up as.
1) Default Vagrantfile
Vagrant.configure('2') do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
end
VirtualBox GUI Name: "nametest_default_1386347922"
Comments: The name defaults to the format DIRECTORY_default_TIMESTAMP.
2) Define VM
Vagrant.configure('2') do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.define "foohost" do |foohost|
end
end
VirtualBox GUI Name: "nametest_foohost_1386347922"
Comments: If you explicitly define a VM, the name used replaces the token 'default'.
3) Set Provider Name
Vagrant.configure('2') do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.provider :virtualbox do |vb|
vb.name = "foohost"
end
end
VirtualBox GUI Name: "foohost"
Comments: If you set the name attribute in a provider configuration block, that name will become the entire name displayed in the VirtualBox GUI.
4) Define VM -and- Set Provider Name
Vagrant.configure('2') do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.define "foohost" do |foohost|
end
config.vm.provider :virtualbox do |vb|
vb.name = "barhost"
end
end
VirtualBox GUI Name: "barhost"
Comments: If you use both methods at the same time, the value assigned to name in the provider configuration block wins.
### You don't actually need the do... end block if it's empty. config.vm.define "foohost" works just fine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment