mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
4.2 KiB
4.2 KiB
Vagrant
TL;DR
# start a box
vagrant up
# connect to the box
vagrant ssh
# print the ssh config snippet to connect to the box
vagrant ssh-config
# (re)provision a box
vagrant provision
vagrant up --provision
# add a box
vagrant add archlinux/archlinux
vagrant add debian/testing64 --provider virtualbox
# list downloaded boxes
vagrant box list
# list outdated boxes
vagrant box outdated
# update a box
vagrant box update
vagrant box update --box generic/gentoo
# remove a box
vagrant box remove archlinux/archlinux
# install autocomplete
vagrant autocomplete install --bash
vagrant autocomplete install --zsh
# install a plugin
vagrant plugin install vagrant-disksize
Usage
All commands need to be run from the box's folder.
-
Install Vagrant.
-
Optionally, create a folder to keep all files in order and move into it:
mkdir test-box cd $_ -
Create a configuration:
vagrant init archlinux/archlinux -
Start the box:
vagrant up # re-provision the box after startup vagrant up --provision -
Connect to the machine:
vagrant ssh
Boxes management
vagrant box add archlinux/archlinux
vagrant box add archlinux/archlinux --provider virtualbox
vagrant box list
vagrant box update
vagrant box update --box generic/gentoo
Install shell's autocomplete
$ vagrant autocomplete install --bash
Autocomplete installed at paths:
- /home/user/.bashrc
$ vagrant autocomplete install --zsh
Autocomplete installed at paths:
- /home/user/.zshrc
Customize a box
Vagrant.configure("2") do |config|
config.vm.box = "archlinux/archlinux"
config.vm.provider "virtualbox" do |vb|
# Vagrant can call any VBoxManage command prior to booting the machine.
# Multiple customize directives will be executed in order.
vb.customize ["modifyvm", :id, "--vram", "64"]
vb.customize ["modifyvm", :id, "--graphicscontroller", "vmsvga"]
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
# Some settings have convenience shortcuts.
vb.name = "xfce4 latest"
vb.cpus = 2
vb.memory = "2048"
vb.default_nic_type = "82543GC"
vb.gui = true
# Skip the guest additions check.
vb.check_guest_additions = false
end
Use environment variables in the provisioning script
Add the variables as argument of the config.vm.provision key:
Vagrant.configure("2") do |config|
config.vm.provision :shell do |shell|
shell.env = {
"STATIC" => "set-in-config",
"FORWARDED" => ENV['HOST_VAR'],
}
shell.inline = <<-SHELL
printenv STATIC FORWARDED
sudo -u vagrant --preserve-env=STATIC,FORWARDED printenv STATIC FORWARDED
SHELL
end
end
Specify the disk size
Install the vagrant-disksize plugin:
vagrant plugin install vagrant-disksize
then set it up:
vagrant.configure('2') do |config|
config.disksize.size = '50GB'
end
Reboot after provisioning
Add one of the following to the box's Vagrantfile:
config.vm.provision "shell", reboot: true
config.vm.provision :shell do |shell|
shell.privileged = true
shell.reboot = true
end