SlideShare a Scribd company logo
Vagrant hackaton
Session Activities can be found here:
https://github.com/akranga/devops-hackathon-1
Vagrant
- Vagrant will mange VM for you
- Describe VM in configuration file
- Can put configuration in Source Control
- You can allow other to contribute
- You have full control on VM
Vagrant
- Ruby powered command line interface to
VM hosted in your Computer
- Supports multiple VM providers
(VirtualBox by default)
- Allows to create reproducible and
portable environments
Vagrant
- Supports run of Multi-VM environments
- Allows to create/restore snapshots of VM
- Allows package environment
- Environment configuration stored in file
(you can put it in git)
Installing Vagrant
- Download and install latest VirtualBox for your OS:
https://www.virtualbox.org/wiki/Downloads
- Download and install latest vagrant for your OS:
http://www.vagrantup.com/downloads.html
- Update PATH Environment System Variable. Add entries:
- VirtualBox location
- C:Program FilesOracleVirtualBox
- Vagrant location
- C:DevOpsvagrantbin
- Might require extra directories
- C:DevOpsvagrantembeddedbin
- C:DevOpsvagrantembeddedmingwbin
- C:DevOpsvagrantembeddedgemsbin
Vagrant Components
- Command Line Interface
- Vagrantfile
- Boxes
- Synced Folder
- Provisioning
- Multi Machine
- Providers
Command Line Interface
Vagrant basic operating model through CLI vagrant command
Running any vagrant subcommand with --help or –h prints context help
$ vagrant init
$ vagrant up
$ vagrant halt
$ vagrant reload
$ vagrant provision
$ vagrant destroy
$ vagrant ssh
$ vagrant ssh-config
Create initial Vagrant configuratoin
Start or create VM if not exists
Power down VM
Restart VM (useful when you change config)
Run Chef or Puppet scripts
Destroy VM as it never existed
Connect to VM if it is running
Prints SSH configuration
Command Line Interface
shell
$ vagrant box list
$ vagrant box add
$ vagrant box remove
$ vagrant box repackage
$ vagrant box outdated
$ vagrant box update
List all vagrant environments on your PC
Add basebox record to vagrant registry
Remove basebox (doesn’t terminate VM)
Make a snapshot of your VM
Deprecates the VM
Checks and updates a VM if it is out-dated
Additional commands to manage your vagrant environments
Vagrantfile
All VM configuration stored in Ruby DSL file. This file can be placed in git.
When you run vagrant up. Vagrant will check following directories.
./Vagrantfile
/home/mitchellh/projects/foo/Vagrantfile
/home/mitchellh/projects/Vagrantfile
/home/mitchellh/Vagrantfile
/home/Vagrantfile
/Vagrantfile
VAGRANT_CWD to change directory where Vagrant is looking for configuration
Boxes
Vagrantfile
Vagrant.configure "2" do |config|
config.vm.box = “my-vm"
config.vm.box_url = “box-url"
end
Minimal Vagrantfile looks like this
Vagrant file contains API versioning.
Vagrantfile (cont)
Vagrantfile
Vagrant.configure "2" do |config|
config.vm.box = “my-vm"
config.vm.box_url = “box-url“
(1..3).each do |i|
config.vm.define "slave-#{i}" do |slave|
slave.vm.provision "shell",
inline: "echo hello from slave #{i}"
end
end
end
How many machines will
run this file?
Modifying scripts
config.vm – to mange VM parameters
Vagrantfile
config.vm.box
config.vm.check_update
config.vm.box_url
config.vm.box_version
config.vm.box.hostname
config.vm.provider
cofnig.vm.synced_folder
Name to be associated with box
By default true. Can disable update checks
URL of the VM to download
Version of the basebox file
Hostname of the VM
By default VirtualBox. Can be other
By default current host dir mounted as
/Vagrant. Can map additional directory
inside VM
Modifying scripts
config.ssh – to customize SSH behavior
Vagrantfile
config.ssh.username
config.ssh.password
config.ssh.private_key_path
config.ssh.insert_key
config.ssh.shell
By default vagrant
No pass by default
Path to your SSH key. By default
/home/.vagrant.d/insecure_private_key
By default true. Can disable to use pass
Shell to open when ssh. By default bash -l
Boxes
To create a VM Vagrant needs a basebox file which is typically
Just Enough Operating System.
Baseboxes can be downloaded from Community websites
www.vagrantbox.es Offsite for Vagrant boxes
http://opscode.github.io/bento/ Vagrant boxes optimized for Chef
You can create your own box using
- Packer (http://packer.io)
- Packer templates for Chef optimized boxes can be found:
https://github.com/opscode/bento
Synced Folder
To enable Vagrant to sync files at your Host and Guest machine
By default mapped directory: /vagrant
Permissions: all files in synced folder are 0777
Vagrant Plugins
Vagrant is extremely pluggable.
You can add/costomize almost everything in Vagrant (such as add
VMWare, AWS or Docker providers), Chef or Puppet provisioning etc.
Vagrant has tons of plugins. Official hosted here:
https://github.com/mitchellh/vagrant/tree/master/plugins
Dog Food: API for Vagrant plugins:
http://en.wikipedia.org/wiki/Eating_your_own_dog_food
Most useful Plugins:
- vagrant-omnibus: Chef for Vagrant VMs
- vagrant-cachier: Cache for packages (can be reused across VMs)
- vagrant-berkshelf: Enable Chef cookbook dependency mechanism
Vagrant plugins command
CLI to manage vagrant plugins.
Will be installed in /home/.vagrant.d/gems
Shell
$ vagrant plugin install
$ vagrant plugin list
$ vagrant plugin uninstall
$ vagrant plugin update
Install vagrant plugin
List of installed plugins
Erase plugin
Check plugin and update with newer version
Activity 1
Run a vagrant box.
Activity 1
Go to /activity1 directory
1. Create a vagrant box file:
$ vagrant init vagrant-hackaton http://opscode-vm-
bento.s3.amazonaws.com/vagrant/vmware/opscode_ubuntu-14.04_chef-
provisionerless.box
2. Run command:
This will create a Vagrant configuration which is pointed to URL.
This is a good manner to specify Valid URL so vagrant config can be
repeatable out of box
$ vagrant up
This will start download image from Internet. Please spare our bandwidth
and terminate this process (CTRL+C). We will add image from our local disk
Activity 1
3. Check if nothing installed
$ vagrant box list
5. Spin up VM:
Vagrant should return no images. Otherwise we might overwrite one with
this activity. Or you might want to change name of VM by modifying
Vagrantfile
4. Add box manually with link to local file
$ vagrant box add vagrant-hackaton PATH-TO-BOX/opscode_ubuntu-
14.04_chef-provisionerless.box
$ vagrant up
6. Connect via SSH
$ vagrant ssh
Activity 1
7. Type command
$ vagrant destroy
8. Destroy VM
in VM
$ uptime
$ exit
Activity 2
Customize VM attributes
Activity 2
Go to /activity2 directory
1. Run command
$ vagrant up
This will bring VM to life. Vagrant will reuse basebox from local file because
activity2 VM has same name as VM from activty1
2. In the VM run command
You should get some HTML text on console. Before exiting SSH sesion
in VM
$ sudo apt-get install –y apache2 curl
$ http://localhost
$ exit
Activity 2
3. Modify Vagrantfile
This will instruct Vagrant to use cache on your Host machine all software
installed inside VM (vagrant requires plugin vagrant-cachier)
4. Modify Vagrantfile as per instructions
Vagrantfile: TODO2
config.vm.network :forwarded_port, guest: XXXXX, host: YYYYY
Vagrantfile: TODO1
config.cache.auto_detect = true
Vagrantfile: TODO3
config.vm.synced_folder "webapp/", "/var/www"
5. Modify Vagrantfile as per instructions
Activity 2
5. after Vagrantfile changes we need to raload VM
$ vagrant reload
6. With your browser open: http://localhost:80801
You will get something like this (on the right)
This is allright. We need to create a HTML
7. Create file webapp/index.html
webapp/index.html
<html>
<head><title>Hello World!</title><head>
<body><h1>Hello Vagrant!</h1></body
</html>
Activity 2
No needs to reload VM (directory will be synced automagically )
8. Refresh your browser at: http://localhost:80801
You will get something like this (on the right)
7. Destroy VM
$ vagrant destroy
Activity 3
Provision DB Server
Activity 3
Go to /activity3 directory
1. Run command
$ vagrant up
Vagrant will fail with
Vagrant:
* Unknown configuration section 'berkshelf'.
* Unknown configuration section 'omnibus'.
2. You need to install additional plugins
$ vagrant plugin install vagrant-berkshelf
$ vagrant plugin install vagrant-omnibus
$ vagrant up
Activity 3
Go to /activity3 directory
1. Run command
$ vagrant up
Vagrantfile has extra configuration that says it will use Chef (Omnibus
packaged) and Berkshelf to download cookbooks. But it doesn’t have plugins
and it will fail:
Vagrant:
* Unknown configuration section 'berkshelf'.
* Unknown configuration section 'omnibus'.
2. Check if plugins installed and install plugins
$ vagrant plugin list
$ vagrant plugin install vagrant-berkshelf
$ vagrant plugin install vagrant-omnibus
$ vagrant up
Activity 3
Go to /activity3 directory
1. Run command
$ vagrant up
Vagrantfile has extra configuration that says it will use Chef (Omnibus
packaged) and Berkshelf to download cookbooks. But it doesn’t have plugins
and it will fail:
Vagrant:
* Unknown configuration section 'berkshelf'.
* Unknown configuration section 'omnibus'.
2. Check if plugins installed and install plugins
$ vagrant plugin list
$ vagrant plugin install vagrant-berkshelf
$ vagrant plugin install vagrant-omnibus
$ vagrant up
Retrospective
How many VMs will this file run?
Vagrantfile
Vagrant.configure "2" do |config|
config.vm.box = “my-vm"
config.vm.box_url = “box-url“
(1..3).each do |i|
config.vm.define "slave-#{i}" do |slave|
slave.vm.provision "shell",
inline: "echo hello from slave #{i}"
end
end
end
Synced folder tricks
Vagrantfile
require 'rbconfig'
is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
Vagrant.configure "2" do |config|
config.vm.box = “my-vm"
config.vm.box_url = “box-url“
config.vm.synced_folder
"webapp/",
"/var/www/html",
nfs: is_windows
end
Synced folder in windows synchronizes in one direction. To enable it to
synchronize in both directions we need to say that host system is
Windows by setting parameter nfs to true
Synced folder tricks
Vagrantfile
require 'rbconfig'
is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
Vagrant.configure "2" do |config|
config.vm.box = “my-vm"
config.vm.box_url = “box-url“
config.vm.synced_folder
"webapp/",
"/var/www/html",
nfs: is_windows
end
Synced folder in windows synchronizes in one direction. To enable it to
synchronize in both directions we need to say that host system is
Windows by setting parameter nfs to true
Synced folder tricks
If Windows host machine you cannot create symlinks in synced directory
However there is a workaround.
1. Add vm customization parameter to Vagrantfile
Vagrantfile
config.vm.customize ["setextradata", :id,
"VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"] if
is_windows
2. Run vagrant up as user Administrator
Shell
$ git clone https://github.com/opscode/bento.git
$ cd bento/packer
bento/packer $ packer build ubuntu-13.10-amd64.json
Creating VM from scratch
Shell
bento/packer $ packer build 
-only=virtualbox 
-var-file=variables.json
ubuntu-13.10-amd64.json
Packer with extra params
variables.json
{
"chef_version": "latest",
"mirror": "../builds/iso/"
}

More Related Content

PPTX
DevOps hackathon Session 2: Basics of Chef
PPTX
Vagrant introduction for Developers
PDF
Deploying Symfony | symfony.cat
PPTX
Vagrant to-aws-flow
PDF
Vagrant for real codemotion (moar tips! ;-))
PDF
Infrastructure = Code
PPT
Learn basic ansible using docker
PPTX
Baking docker using chef
DevOps hackathon Session 2: Basics of Chef
Vagrant introduction for Developers
Deploying Symfony | symfony.cat
Vagrant to-aws-flow
Vagrant for real codemotion (moar tips! ;-))
Infrastructure = Code
Learn basic ansible using docker
Baking docker using chef

What's hot (20)

PDF
Multi-provider Vagrant and Chef: AWS, VMware, and more
PDF
Test-Driven Infrastructure with Chef
PDF
Docker Docker Docker Chef
PDF
Server(less) Swift at SwiftCloudWorkshop 3
PDF
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
PDF
IT Automation with Chef
ODP
Capifony. Minsk PHP MeetUp #11
PDF
Ansible - A 'crowd' introduction
PPTX
Vagrant crash course
PDF
Automation and Ansible
PDF
Deploying PHP Applications with Ansible
KEY
ODP
It Works On My Machine: Vagrant for Software Development
PDF
Deploying an application with Chef and Docker
PDF
Red Hat Satellite 6 - Automation with Puppet
PDF
Vagrant for real (codemotion rome 2016)
KEY
Linecook - A Chef Alternative
PPTX
Orchestration? You Don't Need Orchestration. What You Want is Choreography.
PPT
Python virtualenv & pip in 90 minutes
PPTX
Ansible intro
Multi-provider Vagrant and Chef: AWS, VMware, and more
Test-Driven Infrastructure with Chef
Docker Docker Docker Chef
Server(less) Swift at SwiftCloudWorkshop 3
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
IT Automation with Chef
Capifony. Minsk PHP MeetUp #11
Ansible - A 'crowd' introduction
Vagrant crash course
Automation and Ansible
Deploying PHP Applications with Ansible
It Works On My Machine: Vagrant for Software Development
Deploying an application with Chef and Docker
Red Hat Satellite 6 - Automation with Puppet
Vagrant for real (codemotion rome 2016)
Linecook - A Chef Alternative
Orchestration? You Don't Need Orchestration. What You Want is Choreography.
Python virtualenv & pip in 90 minutes
Ansible intro

Viewers also liked (11)

PDF
DevOps Days Tel Aviv - Serverless Architecture
PDF
Robert kiyosaki pdf
PDF
DevTernity - DevOps with smell
PDF
Antons Kranga Building Agile Infrastructures
PPTX
Java Day Kharkiv - Next-gen engineering with Docker and Kubernetes
PDF
JavaDay Lviv: Serverless Archtiectures
PPTX
Riga dev day: Lambda architecture at AWS
PDF
OpenSlava Infrastructure Automation Patterns
PPTX
DevOps Hackathon: Session 3 - Test Driven Infrastructure
PPTX
OpenSlava 2014 - CloudFoundry inside-out
PDF
Dev ops with smell v1.2
DevOps Days Tel Aviv - Serverless Architecture
Robert kiyosaki pdf
DevTernity - DevOps with smell
Antons Kranga Building Agile Infrastructures
Java Day Kharkiv - Next-gen engineering with Docker and Kubernetes
JavaDay Lviv: Serverless Archtiectures
Riga dev day: Lambda architecture at AWS
OpenSlava Infrastructure Automation Patterns
DevOps Hackathon: Session 3 - Test Driven Infrastructure
OpenSlava 2014 - CloudFoundry inside-out
Dev ops with smell v1.2

Similar to DevOps Hackathon - Session 1: Vagrant (20)

PPTX
Vagrant Up in 5 Easy Steps
PPTX
PDF
Cooking Perl with Chef: Hello World Tutorial
PDF
Create Development and Production Environments with Vagrant
PDF
Puppet and Vagrant in development
PDF
Chef Workshop: Setup Environment with Chef,Vagrant, and Berkshelf
PPTX
Node.js, Vagrant, Chef, and Mathoid @ Benetech
PDF
Create Disposable Test Environments with Vagrant and Puppet
PDF
Create Disposable Test Environments with Vagrant and Puppet
PDF
Preparation study of_docker - (MOSG)
PDF
Continuous Delivery: The Next Frontier
PDF
Intro to vagrant
PDF
Quick & Easy Dev Environments with Vagrant
PDF
Vagrant - Version control your dev environment
PPTX
How To Set a Vagrant Development System
PDF
Oracle Developers APAC Meetup #1 - Working with Wercker Worksheets
PPTX
Vagrant-Overview
PPTX
Virtualization for Developers
PPTX
Setup a Dev environment that feels like $HOME on Windows 10
PPT
Professional deployment
Vagrant Up in 5 Easy Steps
Cooking Perl with Chef: Hello World Tutorial
Create Development and Production Environments with Vagrant
Puppet and Vagrant in development
Chef Workshop: Setup Environment with Chef,Vagrant, and Berkshelf
Node.js, Vagrant, Chef, and Mathoid @ Benetech
Create Disposable Test Environments with Vagrant and Puppet
Create Disposable Test Environments with Vagrant and Puppet
Preparation study of_docker - (MOSG)
Continuous Delivery: The Next Frontier
Intro to vagrant
Quick & Easy Dev Environments with Vagrant
Vagrant - Version control your dev environment
How To Set a Vagrant Development System
Oracle Developers APAC Meetup #1 - Working with Wercker Worksheets
Vagrant-Overview
Virtualization for Developers
Setup a Dev environment that feels like $HOME on Windows 10
Professional deployment

Recently uploaded (20)

PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Geodesy 1.pptx...............................................
PPTX
OOP with Java - Java Introduction (Basics)
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Lecture Notes Electrical Wiring System Components
PDF
composite construction of structures.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
PPT on Performance Review to get promotions
PPTX
Sustainable Sites - Green Building Construction
PPTX
Welding lecture in detail for understanding
PPT
Project quality management in manufacturing
PPTX
Construction Project Organization Group 2.pptx
PDF
Digital Logic Computer Design lecture notes
PPTX
UNIT 4 Total Quality Management .pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Geodesy 1.pptx...............................................
OOP with Java - Java Introduction (Basics)
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
UNIT-1 - COAL BASED THERMAL POWER PLANTS
additive manufacturing of ss316l using mig welding
Lecture Notes Electrical Wiring System Components
composite construction of structures.pdf
Foundation to blockchain - A guide to Blockchain Tech
Structs to JSON How Go Powers REST APIs.pdf
Mechanical Engineering MATERIALS Selection
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPT on Performance Review to get promotions
Sustainable Sites - Green Building Construction
Welding lecture in detail for understanding
Project quality management in manufacturing
Construction Project Organization Group 2.pptx
Digital Logic Computer Design lecture notes
UNIT 4 Total Quality Management .pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf

DevOps Hackathon - Session 1: Vagrant

  • 1. Vagrant hackaton Session Activities can be found here: https://github.com/akranga/devops-hackathon-1
  • 2. Vagrant - Vagrant will mange VM for you - Describe VM in configuration file - Can put configuration in Source Control - You can allow other to contribute - You have full control on VM
  • 3. Vagrant - Ruby powered command line interface to VM hosted in your Computer - Supports multiple VM providers (VirtualBox by default) - Allows to create reproducible and portable environments
  • 4. Vagrant - Supports run of Multi-VM environments - Allows to create/restore snapshots of VM - Allows package environment - Environment configuration stored in file (you can put it in git)
  • 5. Installing Vagrant - Download and install latest VirtualBox for your OS: https://www.virtualbox.org/wiki/Downloads - Download and install latest vagrant for your OS: http://www.vagrantup.com/downloads.html - Update PATH Environment System Variable. Add entries: - VirtualBox location - C:Program FilesOracleVirtualBox - Vagrant location - C:DevOpsvagrantbin - Might require extra directories - C:DevOpsvagrantembeddedbin - C:DevOpsvagrantembeddedmingwbin - C:DevOpsvagrantembeddedgemsbin
  • 6. Vagrant Components - Command Line Interface - Vagrantfile - Boxes - Synced Folder - Provisioning - Multi Machine - Providers
  • 7. Command Line Interface Vagrant basic operating model through CLI vagrant command Running any vagrant subcommand with --help or –h prints context help $ vagrant init $ vagrant up $ vagrant halt $ vagrant reload $ vagrant provision $ vagrant destroy $ vagrant ssh $ vagrant ssh-config Create initial Vagrant configuratoin Start or create VM if not exists Power down VM Restart VM (useful when you change config) Run Chef or Puppet scripts Destroy VM as it never existed Connect to VM if it is running Prints SSH configuration
  • 8. Command Line Interface shell $ vagrant box list $ vagrant box add $ vagrant box remove $ vagrant box repackage $ vagrant box outdated $ vagrant box update List all vagrant environments on your PC Add basebox record to vagrant registry Remove basebox (doesn’t terminate VM) Make a snapshot of your VM Deprecates the VM Checks and updates a VM if it is out-dated Additional commands to manage your vagrant environments
  • 9. Vagrantfile All VM configuration stored in Ruby DSL file. This file can be placed in git. When you run vagrant up. Vagrant will check following directories. ./Vagrantfile /home/mitchellh/projects/foo/Vagrantfile /home/mitchellh/projects/Vagrantfile /home/mitchellh/Vagrantfile /home/Vagrantfile /Vagrantfile VAGRANT_CWD to change directory where Vagrant is looking for configuration
  • 10. Boxes Vagrantfile Vagrant.configure "2" do |config| config.vm.box = “my-vm" config.vm.box_url = “box-url" end Minimal Vagrantfile looks like this Vagrant file contains API versioning.
  • 11. Vagrantfile (cont) Vagrantfile Vagrant.configure "2" do |config| config.vm.box = “my-vm" config.vm.box_url = “box-url“ (1..3).each do |i| config.vm.define "slave-#{i}" do |slave| slave.vm.provision "shell", inline: "echo hello from slave #{i}" end end end How many machines will run this file?
  • 12. Modifying scripts config.vm – to mange VM parameters Vagrantfile config.vm.box config.vm.check_update config.vm.box_url config.vm.box_version config.vm.box.hostname config.vm.provider cofnig.vm.synced_folder Name to be associated with box By default true. Can disable update checks URL of the VM to download Version of the basebox file Hostname of the VM By default VirtualBox. Can be other By default current host dir mounted as /Vagrant. Can map additional directory inside VM
  • 13. Modifying scripts config.ssh – to customize SSH behavior Vagrantfile config.ssh.username config.ssh.password config.ssh.private_key_path config.ssh.insert_key config.ssh.shell By default vagrant No pass by default Path to your SSH key. By default /home/.vagrant.d/insecure_private_key By default true. Can disable to use pass Shell to open when ssh. By default bash -l
  • 14. Boxes To create a VM Vagrant needs a basebox file which is typically Just Enough Operating System. Baseboxes can be downloaded from Community websites www.vagrantbox.es Offsite for Vagrant boxes http://opscode.github.io/bento/ Vagrant boxes optimized for Chef You can create your own box using - Packer (http://packer.io) - Packer templates for Chef optimized boxes can be found: https://github.com/opscode/bento
  • 15. Synced Folder To enable Vagrant to sync files at your Host and Guest machine By default mapped directory: /vagrant Permissions: all files in synced folder are 0777
  • 16. Vagrant Plugins Vagrant is extremely pluggable. You can add/costomize almost everything in Vagrant (such as add VMWare, AWS or Docker providers), Chef or Puppet provisioning etc. Vagrant has tons of plugins. Official hosted here: https://github.com/mitchellh/vagrant/tree/master/plugins Dog Food: API for Vagrant plugins: http://en.wikipedia.org/wiki/Eating_your_own_dog_food Most useful Plugins: - vagrant-omnibus: Chef for Vagrant VMs - vagrant-cachier: Cache for packages (can be reused across VMs) - vagrant-berkshelf: Enable Chef cookbook dependency mechanism
  • 17. Vagrant plugins command CLI to manage vagrant plugins. Will be installed in /home/.vagrant.d/gems Shell $ vagrant plugin install $ vagrant plugin list $ vagrant plugin uninstall $ vagrant plugin update Install vagrant plugin List of installed plugins Erase plugin Check plugin and update with newer version
  • 18. Activity 1 Run a vagrant box.
  • 19. Activity 1 Go to /activity1 directory 1. Create a vagrant box file: $ vagrant init vagrant-hackaton http://opscode-vm- bento.s3.amazonaws.com/vagrant/vmware/opscode_ubuntu-14.04_chef- provisionerless.box 2. Run command: This will create a Vagrant configuration which is pointed to URL. This is a good manner to specify Valid URL so vagrant config can be repeatable out of box $ vagrant up This will start download image from Internet. Please spare our bandwidth and terminate this process (CTRL+C). We will add image from our local disk
  • 20. Activity 1 3. Check if nothing installed $ vagrant box list 5. Spin up VM: Vagrant should return no images. Otherwise we might overwrite one with this activity. Or you might want to change name of VM by modifying Vagrantfile 4. Add box manually with link to local file $ vagrant box add vagrant-hackaton PATH-TO-BOX/opscode_ubuntu- 14.04_chef-provisionerless.box $ vagrant up 6. Connect via SSH $ vagrant ssh
  • 21. Activity 1 7. Type command $ vagrant destroy 8. Destroy VM in VM $ uptime $ exit
  • 23. Activity 2 Go to /activity2 directory 1. Run command $ vagrant up This will bring VM to life. Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1 2. In the VM run command You should get some HTML text on console. Before exiting SSH sesion in VM $ sudo apt-get install –y apache2 curl $ http://localhost $ exit
  • 24. Activity 2 3. Modify Vagrantfile This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier) 4. Modify Vagrantfile as per instructions Vagrantfile: TODO2 config.vm.network :forwarded_port, guest: XXXXX, host: YYYYY Vagrantfile: TODO1 config.cache.auto_detect = true Vagrantfile: TODO3 config.vm.synced_folder "webapp/", "/var/www" 5. Modify Vagrantfile as per instructions
  • 25. Activity 2 5. after Vagrantfile changes we need to raload VM $ vagrant reload 6. With your browser open: http://localhost:80801 You will get something like this (on the right) This is allright. We need to create a HTML 7. Create file webapp/index.html webapp/index.html <html> <head><title>Hello World!</title><head> <body><h1>Hello Vagrant!</h1></body </html>
  • 26. Activity 2 No needs to reload VM (directory will be synced automagically ) 8. Refresh your browser at: http://localhost:80801 You will get something like this (on the right) 7. Destroy VM $ vagrant destroy
  • 28. Activity 3 Go to /activity3 directory 1. Run command $ vagrant up Vagrant will fail with Vagrant: * Unknown configuration section 'berkshelf'. * Unknown configuration section 'omnibus'. 2. You need to install additional plugins $ vagrant plugin install vagrant-berkshelf $ vagrant plugin install vagrant-omnibus $ vagrant up
  • 29. Activity 3 Go to /activity3 directory 1. Run command $ vagrant up Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks. But it doesn’t have plugins and it will fail: Vagrant: * Unknown configuration section 'berkshelf'. * Unknown configuration section 'omnibus'. 2. Check if plugins installed and install plugins $ vagrant plugin list $ vagrant plugin install vagrant-berkshelf $ vagrant plugin install vagrant-omnibus $ vagrant up
  • 30. Activity 3 Go to /activity3 directory 1. Run command $ vagrant up Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks. But it doesn’t have plugins and it will fail: Vagrant: * Unknown configuration section 'berkshelf'. * Unknown configuration section 'omnibus'. 2. Check if plugins installed and install plugins $ vagrant plugin list $ vagrant plugin install vagrant-berkshelf $ vagrant plugin install vagrant-omnibus $ vagrant up
  • 32. How many VMs will this file run? Vagrantfile Vagrant.configure "2" do |config| config.vm.box = “my-vm" config.vm.box_url = “box-url“ (1..3).each do |i| config.vm.define "slave-#{i}" do |slave| slave.vm.provision "shell", inline: "echo hello from slave #{i}" end end end
  • 33. Synced folder tricks Vagrantfile require 'rbconfig' is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) Vagrant.configure "2" do |config| config.vm.box = “my-vm" config.vm.box_url = “box-url“ config.vm.synced_folder "webapp/", "/var/www/html", nfs: is_windows end Synced folder in windows synchronizes in one direction. To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true
  • 34. Synced folder tricks Vagrantfile require 'rbconfig' is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) Vagrant.configure "2" do |config| config.vm.box = “my-vm" config.vm.box_url = “box-url“ config.vm.synced_folder "webapp/", "/var/www/html", nfs: is_windows end Synced folder in windows synchronizes in one direction. To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true
  • 35. Synced folder tricks If Windows host machine you cannot create symlinks in synced directory However there is a workaround. 1. Add vm customization parameter to Vagrantfile Vagrantfile config.vm.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"] if is_windows 2. Run vagrant up as user Administrator
  • 36. Shell $ git clone https://github.com/opscode/bento.git $ cd bento/packer bento/packer $ packer build ubuntu-13.10-amd64.json Creating VM from scratch
  • 37. Shell bento/packer $ packer build -only=virtualbox -var-file=variables.json ubuntu-13.10-amd64.json Packer with extra params variables.json { "chef_version": "latest", "mirror": "../builds/iso/" }