This document provides an introduction to using Vagrant, including:
- What Vagrant is and why it is useful for sharing identical development environments across teams
- How to install Vagrant on Linux and configure a Vagrantfile
- Key concepts like providers, boxes, and provisioners for setting up and managing virtual machines
- Common Vagrant commands for accessing, halting, and sharing virtual machines
2. Wait What's That?
● A vagrant is someone who moves a lot from
place to place because he has no permanent
home or job, and have to ask for or steal
things in order to live.
● Vagrant is a package manager for an entire
development environment(VMs basically)
3. Why Do I Need Vagrant?
● Say goodbye to my machine excuse.
● Identical development environment for
everyone in the team
● Sharing apps and scripts is a lot more easier
4. Hmm Interesting!!
Pre-installed on Linux?
● No! cause it's EASY :D
● Go to http://www.vagrantup.com/downloads
● Download the proper package for your operating
system and architecture.
● You can choose the version (latest or old ones)
5.
6. Linux(Debian/Ubuntu) Case?
● Go to the directory where you downloaded the
package. Eg: cd /home/haifa/Downloads
● Depending on the package type:
– Deb package:
dpkg -i vagrant_version_architecture.deb
– RPM package convert it to .deb using alien
or
– rpm -ivh vagrant_version_architecture.rpm
installez rpm (sudo apt-get install rpm)
7. How can I set up my environment?
● You should make the difference between:
– A Provider: software responsible for creating and
managing the virtual machines used by Vagrant.
Eg: vmware or virtualbox in our case.
– A Provisioner: software/developer doing some
tasks using the vm instance already provided: set
up the virtual server, install all necessary software
and execute different tasks. The most used
provisioners are: Puppet, Chef.. or via Shell Script.
8. Clear. That's all?
● Two more words you should know:
– A box: a package containing a representation of a
virtual machine running a specific operating
system, for a specific Provider.(base image to
quickly clone a virtual machine)
– Vagrantfile: a file in which the vagrant
configuration is based.
It shall be placed in your repository root. In this
file you will define which base box you want.
9. Vagrantfile ?
● The primary function of the Vagrantfile is to
describe the type of machine required for a
project, and how to configure and provision
these machines.
● Vagrant is meant to run with one Vagrantfile per
project, which allows other developers involved
in the project to check out the code, run
vagrant up, and be on their way. Vagrantfiles
are portable across every platform Vagrant
supports.
10. Okay! Let me make a Vagrantfile..
● Let's read it together:
●
This will place a Vagrantfile in your current
directory. Let's take a look at the Vagrantfile.
Don't be afraid if it looks intimidating, it is filled
with comments and examples.
11. # -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "base"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
12. don't change it unless you know
what you're doing haha
● The Vagrantfile is a very flexible configuration
format. Since it is just Ruby, there is a lot you
can do with it. However, in that same vein,
since it is Ruby, there are a lot of ways you
can shoot yourself in the foot.
● The syntax of Vagrantfiles is Ruby,
but knowledge of the Ruby programming
language is not necessary to make
modifications to the Vagrantfile, since it is
mostly simple variable assignment.
13. Available Configuration Options
● Minimum Vagrant
Version:Vagrant.require_version ">= 1.3.5"
● config.vm.hostname
● config.vm.network
● config.vm.post_up_message
… you can check
https://docs.vagrantup.com/v2/vagrantfile/ for
more configuration tricks .
14. Accessing my VM?
● Vagrant allows you to access via ssh to your
VM (that's the default method)
● The settings within config.ssh relate to
configuring how Vagrant will access your
machine over SSH. As with most Vagrant
settings, the defaults are typically fine, but you
can fine tune whatever you'd like.
● config.ssh.username
● config.ssh.password
● config.ssh.port and so on
15. Useful commands?
● Vagrant box add
● Vagrant box list
● Vagrant init
● Vagrant up
● Vagrant status
● Vagrant ssh
● Exit
● Vagrant halt
16. Sharing it with the team?
● Vagrant Share requires an account with
HashiCorp's Atlas to be used.
● Vagrant connect
● vagrant share
17. Downloading boxes
● Go to https://vagrantcloud.com/ and choose
one of hundreds of linux boxes :)
18. Hope it was great as a start!
● Stop everything and vagrant up :D
Haifa Ftirich CLLFST