DevOps Series: Defining and Sharing Testable Machine Configurations with vagrant


Published on

A simple explanation (with examples) of what can be accomplished with Vagrant, a very useful tool to effectively define and share machine configurations, in order to ensure everyone on your team is running the exact same environment.

Published in: Software, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

DevOps Series: Defining and Sharing Testable Machine Configurations with vagrant

  1. 1. Defining testable Machine Configurations with Vagrant 30-40 minutes Updated in June 2014
  2. 2. What? Vagrant is used for building reproducible and testable machine configurations. In other words, coding your infrastructure. You just define a base box (e.g. Ubuntu 12.04) and all configurations (depending on your provider), packages to install and so on. You install a VM provider (e.g. VirtualBox), run vagrant up and you’re good to go.
  3. 3. Why? ● Machine configurations become a liability when you need to ensure your software is correct (did it break because of your environment or because the code is actually faulty?) ● It’s hard to make sure everyone in a team has the exact same machine setup. ● Sometimes it takes careful configuration to make something work and you want to avoid having to do it for every new machine you work on. ● The need to be able to remotely configure (sometimes complex) infrastructures in the cloud.
  4. 4. Who is it good for? For those who: ● need to make sure their entire team has the exact same environment set up so ● are responsible for configuring and setting up environments for others and want to optimize the process; ● don’t want to waste time applying the same hacks or complex configuration steps for each thew machine they use (common scenario).
  5. 5. Technical details ● Supported Hosts ○ Windows, Linux, MacOS ● Supported Guests ○ Everything *nix and Windows ● Supported Virtualization Providers ○ VirtualBox ○ VMWare (Workstation and Fusion) ○ Hyper V ○ AWS ○ Others (via plugins)
  6. 6. Your first Vagrantfile This is a simple Vagrantfile that uses one of the most common boxes found in VagrantCloud. You need to run vagrant box add hashicorp/precise32 prior to running it. Vagrant.configure(2) do |config| = "hashicorp/precise32" config.vm.provider "virtualbox" do |v| v.gui = true end end (This setup will get you a bare-bones Ubuntu 12.04 LTS Virtualbox machine.)
  7. 7. Basic Workflow This is the simplest possible example of how to get from zero to sixty using Vagrant (after you’ve installed Vagrant itself and a simple provider like VirtualBox). ● run vagrant box add to add a base box definition to your collection ● create a new directory ● cd into that directory and run vagrant init; this will create a blank Vagrantfile in that directory ● edit said Vagrantfile adding options for your box (using one of the boxes you’ve added via vagrant box add as base) ● run vagrant up If there were no errors, you should have a new VirtualBox instance running (note that it may have no GUI - you can use the Vagrantfiles shown in previous slides).
  8. 8. Basic provisioning Provisioning just means installing packages and/or further configuring your newly-created box. For example, if you create an Ubuntu box, you might want to have Apache web server installed beforehand: Vagrant.configure(2) do |config| # … other configurations config.vm.provision "shell",inline: "apt-get update" config.vm.provision "shell",inline: "apt-get install apache2 --assume- yes" end
  9. 9. Advanced provisioning Vagrant supports a large number of third-party provisioners which can be used to further configure your machine. Some of the most commonly-used provisioners (apart from inline scripting as in the previous slide) are as follows: ● Files (for example, to share environment between host and guest) ● Puppet ● Chef ● CFEngine ● Ansible ● Salt
  10. 10. Useful commands ● vagrant up - Creates a VM and starts it (or just start it if it’s already installed) ● vagrant provision - Run any provisioning you might have set up for the current box. ● vagrant reload - Restarts the VM taking into account modifications made to Vagrantfile ● vagrant box list - Show all available boxes (i.e., boxes you have added).
  11. 11. Heads-up I ● In order to use some useful commands like vagrant ssh (used to ssh into your vagrant box), you need some unix commands (in this case, ssh). This would seem to be an issue if you’re running Windows, but you have many options here: some are Installing Git (it comes with a few utils) and using Cygwin or MinGW. ● Starting from version 1.6, Vagrant has added full support for Windows Guests. (Note that Support for Windows Hosts have been supported since earlier versions.)
  12. 12. Heads-up II ● Most base (Linux) boxes have no Desktop Environment (like Gnome or XFCE) installed by default. This means that, if you want to access your Linux box via a GUI (menus and buttons), you have to install it yourself. ● (Setting v.gui = true in the config file does not install a Desktop Environment for your VM!) For a basic Ubuntu Virtualbox box with a GUI, see This bit of code on GitHub.
  13. 13. References ● Official Vagrant Docs ● Summary of Commands ● Vagrant Provisioning