[ About | Licence | Contacts ]
Written by Oleksandr Gavenko (AKA gavenkoa), compiled on 2018-11-21 from rev fcdd583e8795+.

Vagrant

Changing Vagrant home directory

Set VAGRANT_HOME env var, like:

VAGRANT_HOME=d:\srv\vagrant

Default is ~/.vagrant.d for Linux and %USERPROFILE%\.vagrant.d for Windows.

https://www.vagrantup.com/docs/other/environmental-variables.html
Environmental Variables. VAGRANT_HOME.
https://www.vagrantup.com/docs/vagrantfile/
Load Order and Merging.

Managing names

Vagrant VM name:

config.vm.define "NAME"

VirtualBox name:

config.vm.provider :virtualbox do |vb|
  vb.name = "NAME"
end

Host name:

config.vm.hostname = "NAME"

Managing resources

https://unix.stackexchange.com/questions/176687/set-storage-size-on-creation-of-vm-virtualbox https://askubuntu.com/questions/317338/how-can-i-increase-disk-size-on-a-vagrant-vm https://stackoverflow.com/questions/49822594/vagrant-how-to-specify-the-disk-size https://github.com/sprotheroe/vagrant-disksize

Managing boxes

Adding new box from catalog:

$ vagrant box add ubuntu/trusty64

Checking for box updates:

$ cd $BOXDIR
$ vagrant box outdated

or:

$ vagrant box outdated --global

Disable checking for update each time you call vagrant command:

Vagrant.configure("2") do |config|
  config.vm.box_check_update = false
end

Download box update:

$ vagrant box update

Note

vagrant box update does not magicall updates your existing boxes. In just download updated versions. To install new versio you need to destroy and install new boxes:

$ vagrant destroy
$ vagrant up

To remove box at specific version:

$ vagrant box remove laravel/homestead --box-version 1.1.0

To get list of boxes with corresponding versions:

$ vagrant box list
$ vagrant global-status
https://www.vagrantup.com/docs/cli/box.html
Command: vagrant box.
https://www.vagrantup.com/docs/boxes/versioning.html
Box Versioning.

Managing plugins

https://www.vagrantup.com/docs/cli/plugin.html
Command: vagrant plugin.
https://github.com/hashicorp/vagrant/wiki/Available-Vagrant-Plugins
List of vagrant plugins.

Debugging Vagrant

Add environment variavle:

VAGRANT_LOG=warn vagrant ssh
VAGRANT_LOG=info vagrant ssh
VAGRANT_LOG=debug vagrant ssh
https://www.vagrantup.com/docs/other/environmental-variables.html
Environmental Variables. VAGRANT_LOG.

Running individual provisioning scripts

You may give name to provisioning script:

Vagrant.configure("2") do |config|
  config.vm.provision 'user_ssh', type: :shell, privileged: false do |s|
    ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
    s.inline = "echo #{ssh_pub_key} >> /home/$USER/.ssh/authorized_keys"
  end
  config.vm.provision 'root_ssh', type: :shell, privileged: true do |s|
    ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
    s.inline = "mkdir /root/.ssh/; echo #{ssh_pub_key} >> /root/.ssh/authorized_keys"
  end
  ...
end

and apply them individually:

vagrant provision --provision-with user_ssh
vagrant provision --provision-with root_ssh
vagrant provision --provision-with user_ssh,root_ssh

Working with Alpine Linux

Install plugin:

$ vagrant plugin install vagrant-alpine
Installing the 'vagrant-alpine' plugin. This can take a few minutes...
Installed the plugin 'vagrant-alpine (0.3.0)'!

Create Vagrantfile:

$ vagrant init maier/alpine-3.6-x86_64
https://app.vagrantup.com/maier/boxes/alpine-3.6-x86_64
AlpineLinux v3.6.2 with VirtualBoxGuestAdditions
https://app.vagrantup.com/maier
maier boxes.
https://github.com/maier/vagrant-alpine
Home page of vagrant-alpine plugin.
https://app.vagrantup.com/generic/boxes/alpine36
Generic box.
https://app.vagrantup.com/generic/boxes
Generic boxes.