I'm trying to set host name for VM. Here my Vagrantfile:
Vagrant::Config.run do |config|
config.vm.box = "opensuse-12.3-32"
config.vm.define :web do |web_config|
web_config.vm.hostname "web.my.net"
web_config.vm.forward_port 80, 7080
web_config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet"
puppet.module_path = "puppet/modules"
puppet.manifest_file = "base.pp"
end
end
end
But it leads to the following error:
/home/coder/vagrant/opensuse/Vagrantfile:40:in `block (2 levels) in <top (required)>': undefined method `hostname' for #<VagrantPlugins::Kernel_V1::VMConfig:0x00000002748fb8> (NoMethodError)
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/config/v1/loader.rb:37:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/config/v1/loader.rb:37:in `load'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/config/loader.rb:104:in `block (2 levels) in load'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/config/loader.rb:98:in `each'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/config/loader.rb:98:in `block in load'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/config/loader.rb:95:in `each'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/config/loader.rb:95:in `load'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/environment.rb:335:in `machine'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/plugin/v2/command.rb:134:in `block in with_target_vms'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/plugin/v2/command.rb:167:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/plugin/v2/command.rb:167:in `block in with_target_vms'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/plugin/v2/command.rb:166:in `map'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/plugin/v2/command.rb:166:in `with_target_vms'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/plugins/commands/status/command.rb:16:in `execute'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/cli.rb:38:in `execute'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/environment.rb:484:in `cli'
from /opt/vagrant/embedded/gems/gems/vagrant-1.3.1/bin/vagrant:96:in `<top (required)>'
from /opt/vagrant/bin/../embedded/gems/bin/vagrant:23:in `load'
from /opt/vagrant/bin/../embedded/gems/bin/vagrant:23:in `<main>'
I'm using Vagrant 1.3.1 under Ubuntu 12.10. (64 bit) and OpenSuSe 12.3 (32 bit) as VM.
What you have is a mismatch between your code and the version of the Vagrant API you are using.
config.vm.host_name
.config.vm.hostname
.Try:
web_config.vm.hostname = "web.my.net"
As per issue #1974, setting hostname you should be using => config.vm.hostname = "web.my.net"
So the block should look like
config.vm.define :web do |web_config|
web_config.vm.hostname = "web.my.net"
web_config.vm.forward_port 80, 7080
web_config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet"
puppet.module_path = "puppet/modules"
puppet.manifest_file = "base.pp"
end
end
You can even generate some random hostname by using code below
config.vm.hostname = "devops#{rand(01..99)}.vagrant.vm}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With