type | slideOptions | ||||||||
---|---|---|---|---|---|---|---|---|---|
slide |
|
-
Remember:
If you can't git diff a file format, it's broken.
-
Infrastructure as code
Vagrant is a tool for building and managing virtual machine environments in a single workflow.
-
Initial release 2010 by Mitchell Hashimoto, now HashiCorp
-
HashiCorp develops open-source DevOps/Cloud tools like Vagrant, TerraForm...
- Provisioners
- Tool for configuring the boxes (install software on machine)
- Examples: shell scripts, Chef, Puppet..
- Providers
- "Backend" on which the box is based
- Examples: VirtualBox, Hyper-V, AWS, Docker...
- Developing software
- Set up consistent development environment
- Share environment with others
- Testing software, workflows...
- Disposable environments
- Consistent workflows
- More general
- Simple way to setup virtual machine
- Reproducible environment
- Strong focus on workflow consistency
- (Re)use existing images
- Automatize VM creation and configuration
- Easier than with VirtualBox CLI and shell scripts
- Store in Git-friendly format
- For us:
- Management of VirtualBox VMs (testing, developing...)
- Sharing of VMs (debugging, workshops...)
vagrant init USERNAME/BOXNAME or URL
- Initializes repository in current directory
- Creates
Vagrantfile
-> Text file (Git friendly)
vagrant up
- Create VM and start it
- VM is stored in
${HOME}/.vagrant.d/boxes
(overruled byVAGRANT_HOME
)
vagrant ssh
- Connect to VM via ssh
vagrant destroy
- Stops the virtual machine and removes its disk
vagrant box list
- Show available boxes
vagrant box remove NAMEOFBOX
- Remove a box completely
vagrant suspend
- Suspends machine (sleep)
vagrant halt
- Shuts down machine keeping changes
vagrant reload --provision
orvagrant provision
- Rebuild (partially) build image
Details available in vagrant_demo.md
- File
Vagrantfile
- Contains configuration of VM
- Ruby script
- Supplementary files, scripts etc. for configuring VM
- Example:
bootstrap.sh
- Example:
- Files are usually text files (Git friendly)
-
Install VirtualBox
-
Install Vagrant (ideally from homepage so it is a recent release)
-
Create
Vagrantfile
and specify imageVagrant.configure("2") do |config| config.vm.box = "ajaust/sse-first-steps" config.vm.box_version = "0.1.0" end
-
Alternative:
vagrant init ajaust/sse-first-steps
-
Start VM with
vagrant up
-
Vagrant mounts shared folders
- Check output when VM starts
default: Mounting shared folders...
- Files can be exchanged between Guest and Host (bidirectional)
-
Default:
- Directory containing
Vagrantfile
mounted to/vagrant
in Guest
- Directory containing
-
Repository of premade boxes: https://app.vagrantup.com/
-
Pack box:
vagrant package --base "NAMEOFVM" --output BOXNAME.box
NAMEOFVM
is name as shown in VirtualBoxBOXNAME
name to store box to
-
Publish own boxes by uploading to Vagrant Cloud
- Open-source tool
- Git-friendly way of configuring VMs
- Simple management of VMs
- Creates consistent workflows
- Flexible due to big variety of provisioners and providers
- Premade images can be used and shared