Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a more clear name for Vagrant machine

Tags:

vagrant

I am working with Vagrant and it is a wonderful tool for virtualized enviroments. But I have a doubts about how VirtualBox changes the name of VM created.

I have this Vagrantfile configuration

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.hostname = "ubuntu"

  config.vm.box = "ubuntu-12.04"

  config.vm.network :private_network, ip: "33.33.33.13"

  config.berkshelf.enabled = true

end 

When I run vagrant up the virtualbox tool creates my machine with a different name.

roberto@rcisla-pc:~/myface$ VBoxManage list vms
"myface_default_1390750040" {eed39077-32da-44e5-961f-2bb772a2bf31}

Why virtualbox creates the machine with the name myface_default_1390750040 when I configured in the Vagrantfile a different name, in this case ubuntu-12.04.

This is my myface cookbook structure

 .
    ├── attributes
    │   └── default.rb
    ├── Berksfile
    ├── Berksfile.lock
    ├── chefignore
    ├── definitions
    ├── files
    │   └── default
    ├── Gemfile
    ├── libraries
    ├── LICENSE
    ├── metadata.rb
    ├── providers
    ├── README.md
    ├── recipes
    │   └── default.rb
    ├── resources
    ├── templates
    │   └── default    │       
    ├── test
    │   └── integration
    │       └── default
    │           └── serverspec
    │               ├── default
    │               │   ├── test_spec.rb
    │               │   └── demo_spec.rb
    │               └── spec_helper.rb
    ├── Thorfile
    └── Vagrantfile

I don't understand why VirtualBox take the name relative to the cookbook and not take the name ubuntu-12.04

I am using

  • Vagrant 1.3.5
  • VirtualBox 4.3.5 r91406
like image 554
Robert Avatar asked Sep 10 '25 22:09

Robert


1 Answers

You can add a config.vm.define block in your vagrant file.

E.g:

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.synced_folder ".", "/vagrant", type: "nfs"

  config.vm.define "{YOUR NICE NAME HERE}" do |web|

    web.vm.box       = "CentOs"
    web.vm.box_url   = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box"
    web.vm.hostname  = 'dev.local'

    web.vm.network :forwarded_port, guest: 90, host: 9090
    web.vm.network :private_network, ip: "22.22.22.11"

    web.vm.provision :puppet do |puppet|
      puppet.manifests_path = "puppet/manifests"
      puppet.manifest_file  = "web.pp"
      puppet.module_path    = "puppet/modules"
      puppet.options        = ["--verbose", "--hiera_config /vagrant/hiera.yaml", "--parser future"]
    end

  end

end

This way you will see your defined name back when you check the list in virtual box. But remember that Vagrant will always append a random string behind the VM's name, since it needs to identify the correct machine when running multiple vm's of the same vagrant file.

like image 78
cocheese Avatar answered Sep 13 '25 17:09

cocheese