solcaj
9/26/2019 - 1:43 PM

BASIC Vagrant

Vagrantfile

  • primary config location, located in Project folder
  • config syntax is ruby of Key / Value pair
  • Vagrant uses API versions for its configuration file, currently version 2

Basic Configuration of the Vagrant Box

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

  config.vm.box = "ubuntu/trusty64"                                   # The box NAME to use, will be downloaded 
  config.vm.network "private_network", ip: "10.0.0.10"
  # or config.vm.network :private_network, ip: "192.168.33.10"        # create priv network  
  config.vm.hostname = "icatbeta"                                     # set hostname
end

Sync Folder

config.vm.synced_folder "./", "/var/www", create: true, group: "www-data", owner: "www-data"

where the args are

argdescription
./Host machine folder (OS X) to be shared with the machine .. Also current dir where Vagrantfile is located
/var/wwwThe target machine (linux) folder where it should be moounted
create: truespecifies that if the target folder (/var/www) does not exist, then create it automatically.
group: “www-data” and owner: “www-data”specifies the owner and the group of the shared folder inside the VM. By default most web servers use www-data as the owner accessing the files, it’s a good practice to set the ownership to this user

How To define the provisioning

Note that Vagrant will provision the virtual machine only once on the first run, any subsequent provisioning must be executed with the --provision flag either vagrant up --provision or vagrant reload --provision

Provisioning the box Key Value

  config.vm.provision "shell", inline: "echo "hello"
  config.vm.provision "bootstrap", type: "shell", path: "provision-centos74ICAT.sh"

Ruby Syntax version

config.vm.provision "bootstrap", type: "shell"  do |s|
   s.path = "provision-centos74ICAT.sh"
end

config.vm.provision "shell"do |s|
  s.inline="echo "hello"
end 

Multiple provision providers

 config.vm.provision "bootstrap-system", type: "shell", path: "vm_provision/provision-ubuntu.sh"
 config.vm.provision "bootstrap-icat", type: "shell"  do |s|
     s.path = "vm_provision/bootstrap-icat.sh"
 end

will start the 2 provisioning scripts see /Users/sxxx/_Projects/insti/ICAT/Virtualization/ICAT-Beta-ubuntu/vm_provision

Vagrant ALM commands

 $ vagrant init   # create Vagrantfile if not present
 $ vagrant up 
 $ vagrant status
 $ vagrant destroy 

Vagrant login + execute commands

  $ vagrant ssh 
  $ vagrant ssh -- cmd1;cmd2

Force reload of proviioning

$ vagrant reload --provision 

Vagrant box commands

  $ vagrant box list, list my boxes (see Virtualbox)  # Vagrantfile 
  $ vagrant box add <mytitle> <uri> (uri: URL or user/box (hashicorp/trusty64))