· 6 years ago · Oct 15, 2019, 06:46 AM
1# Vagrantfile
2- primary config location, located in Project folder
3- config syntax is ruby of Key / Value pair
4- Vagrant uses API versions for its configuration file, currently version 2
5
6## Basic Configuration of the Vagrant Box
7
8``` Ruby
9Vagrant.configure("2") do |config|
10
11 config.vm.box = "ubuntu/trusty64" # The box NAME to use, will be downloaded
12 config.vm.network "private_network", ip: "10.0.0.10"
13 # or config.vm.network :private_network, ip: "192.168.33.10" # create priv network
14 config.vm.hostname = "icatbeta" # set hostname
15end
16```
17### Sync Folder
18
19```
20config.vm.synced_folder "./", "/var/www", create: true, group: "www-data", owner: "www-data"
21```
22where the args are
23
24| arg | description |
25| :----: | :--- |
26| `./` | Host machine folder (OS X) to be shared with the machine .. Also current dir where `Vagrantfile` is located |
27| `/var/www` | The target machine (linux) folder where it should be moounted |
28| `create: true` | specifies that if the target folder (/var/www) does not exist, then create it automatically.|
29| `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 |
30
31## How To define the provisioning
32> 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`
33
34### Provisioning the box Key Value
35```
36 config.vm.provision "shell", inline: "echo "hello"
37 config.vm.provision "bootstrap", type: "shell", path: "provision-centos74ICAT.sh"
38```
39### Ruby Syntax version
40
41```Ruby
42config.vm.provision "bootstrap", type: "shell" do |s|
43 s.path = "provision-centos74ICAT.sh"
44end
45
46config.vm.provision "shell"do |s|
47 s.inline="echo "hello"
48end
49```
50
51### Multiple provision providers
52```Ruby
53 config.vm.provision "bootstrap-system", type: "shell", path: "vm_provision/provision-ubuntu.sh"
54 config.vm.provision "bootstrap-icat", type: "shell" do |s|
55 s.path = "vm_provision/bootstrap-icat.sh"
56 end
57```
58
59will start the 2 provisioning scripts see `/Users/sxxx/_Projects/insti/ICAT/Virtualization/ICAT-Beta-ubuntu/vm_provision`
60
61
62
63## Vagrant ALM commands
64
65```Bash
66 $ vagrant init # create Vagrantfile if not present
67 $ vagrant up
68 $ vagrant status
69 $ vagrant destroy
70```
71
72## Vagrant login + execute commands
73
74```Bash
75 $ vagrant ssh
76 $ vagrant ssh -- cmd1;cmd2
77```
78## Force reload of proviioning
79
80```
81$ vagrant reload --provision
82```
83
84## Vagrant box commands
85
86```Bash
87 $ vagrant box list, list my boxes (see Virtualbox) # Vagrantfile
88 $ vagrant box add <mytitle> <uri> (uri: URL or user/box (hashicorp/trusty64))
89```