我正在使用 Vagrant,它是虚拟化环境的一个很棒的工具。但我对 VirtualBox 如何更改创建的虚拟机的名称有疑问。
我有这个 Vagrantfile 配置
# -*- 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
当我运行 vagrant up 时,virtualbox 工具会使用不同的名称创建我的机器。
roberto@rcisla-pc:~/myface$ VBoxManage list vms
"myface_default_1390750040" {eed39077-32da-44e5-961f-2bb772a2bf31}
当我在 Vagrantfile 中配置不同的名称(在本例中为 ubuntu-12.04)时,为什么 virtualbox 会创建名称为 myface_default_1390750040 的计算机。
这是我的myface食谱结构
.
├── 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
我不明白为什么 VirtualBox 采用与食谱相关的名称而不采用 ubuntu-12.04 这个名称
我正在使用
- Vagrant 1.3.5
- VirtualBox 4.3.5 r91406
最佳答案
您可以在 vagrant 文件中添加 config.vm.define block 。
例如:
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
这样,当您检查虚拟框中的列表时,您将看到您定义的名称。但请记住,Vagrant 始终会在虚拟机名称后面附加一个随机字符串,因为在运行同一个 vagrant 文件的多个虚拟机时,它需要识别正确的机器。
关于vagrant - 如何为 Vagrant 机器获得更清晰的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21410099/