ubuntu - Vagrant config terminology -


tl;dr; can me understand difference between these "names" defined in vagrantfile?

  1. config.vm.define "worker"
  2. box.vm.box = "ots-box"
  3. box.vm.host_name = "worker"
  4. vb.name = "barhost"

while trying change hostname of vagrant instance had, lost in vagrantfile syntax. have changed hostname other things (network) isn't working. suspect i've changed has lead vagrant configure box particular way, caused issue.

vagrant.configure("2") |config|   config.vm.define "worker".to_sym |box|     box.vm.box = "ots-box"     box.vm.box_url = "http://testing.xxx.com.s3.amazonaws.com/ots-fe.box"     box.vm.host_name = "worker" end 

i suppose it's irrelevant i'm trying create ubuntu box on mac el-capitan oracle virtualbox , vagrant version 1.7.4.


documentation says: config.vm.box - configures box machine brought against. value here should name of installed box or shorthand name of box in hashicorp's atlas.

example here introduces term vb.name:

vagrant.configure('2') |config|   config.vm.box = "precise64"   config.vm.box_url = "http://files.vagrantup.com/precise64.box"   config.vm.define "foohost" |foohost|   end   config.vm.provider :virtualbox |vb|       vb.name = "barhost"   end end 

i'll try answer points points:

first following syntax

vagrant.configure("2") |config|      config.vm.define "worker".to_sym |box|     box.vm.box = "ots-box"     box.vm.box_url = "http://testing.xxx.com.s3.amazonaws.com/ots-fe.box"     box.vm.host_name = "worker"    end 

is used if have multiple vms running (https://docs.vagrantup.com/v2/multi-machine/) need define name vm, in case worker within next block parameters set worker vm , make ruby syntax happy need define variable name (box)

so if have single vm within vagrantfile, not need syntax, can have

vagrant.configure("2") |config|        config.vm.box = "ots-box"     config.vm.box_url = "http://testing.xxx.com.s3.amazonaws.com/ots-fe.box"     config.vm.hostname = "worker"    end 

second, config/box.vm.box points vagrant box important concept of vagrant each vm spin must created against existing box. can download box internet (vagrant atlas, http://www.vagrantbox.es/) or make box yourself. can review available boxes installed on machine running vagrant box list. if box set in vagrantfile not available in available box, vagrant try download (so if point ubuntu/trusty64, if did not install it, vagrant download https://atlas.hashicorp.com/ubuntu/boxes/trusty64, assuming available provider)

third, config/box.vm.hostname variable you're interested (not hostname vs host_name), doc

config.vm.hostname - hostname machine should have. defaults nil. if nil, vagrant won't manage hostname. if set string, hostname set on boot.

so if set variable in vagrantfile , boot machine, hostname variable in ubuntu resolved same value. example, following vagrantfile

vagrant.configure(2) |config|   ...   config.vm.box = "ubuntu/trusty64"   config.vm.hostname = "ubuntu"   ... 

from vm, get

fhenri@machine:~/project/examples/vagrant/ubuntu$ vagrant ssh welcome ubuntu 12.04.1 lts (gnu/linux 3.2.0-29-virtual x86_64)   * documentation:  https://help.ubuntu.com/ last login: tue jan  5 10:21:54 2016 172.16.42.1 vagrant@ubuntu:~$ hostname ubuntu 

finally name topic, config/box.vm.name used name of vm provider (in case virtualbox), quite explained following answer


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -