9/26/2019 - 1:43 PM

BASIC Vagrant


  • 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| = "ubuntu/trusty64"                                   # The box NAME to use, will be downloaded "private_network", ip: ""
  # or :private_network, ip: ""        # create priv network  
  config.vm.hostname = "icatbeta"                                     # set hostname

Sync Folder

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

where the args are

./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: ""

Ruby Syntax version

config.vm.provision "bootstrap", type: "shell"  do |s|
   s.path = ""

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

Multiple provision providers

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

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))