VAGRANT
Larry Nung
AGENDA
Introduction
Installion
Command
SSH in Windows
Getting Started
Vagrantfile
Provisioning
Reference
Q & A
INTRODUCTION
INTRODUCTION
INTRODUCTION
INTRODUCTION
Vagrant
Provider
Provision
Vagrantfile
Box
TRUSTED BY
PROVIDERS
COMMAND
COMMAND
INSTALLION
INSTALLION
 Provider
 Virtualbox
 VMware
 AWS
 Digitalocean
 Docker
 Hyperv
 Rackspace
 Parallels
INSTALLION
 Vagrant
INSTALLION
 SSH tool
 Git
 Putty
SSH IN WINDOWS
WITH PUTTY
WITH VAGRANT SSH
WITH GIT SSH
GETTING STARTED
VAGRANT INIT
$ vagrant init hashicorp/precise32
VAGRANT UP
$ vagrant up
VAGRANT BOX LIST
$ vagrant box list
VAGRANT SSH
$ vagrant ssh
VAGRANT SSH
VAGRANT PACKAGE
$ vagrant package
VAGRANT HALT
 $ vagrant halt
VAGRANT DESTROY
 $ vagrant destroy
VAGRANT BOX REMOVE
$ vagrant box remove hashicorp/precise32
VAGRANTFILE
VAGRANTFILE
 Describe the type of machine required for a project,
and how to configure and provision these machines.
VAGRANTFILE INHERITANCE
Project
Vagrantfile
Home
Vagrantfile
Box Vagrantfile
MACHINE SETTINGS
 config.vm.box
 config.vm.box_url
 config.vm.box_check_update
 config.vm.network
 config.vm.provider
 config.vm.provision
 config.vm.synced_folder
 e.t.c
FORWARDED PORTS
Vagrant.configure("2") do |config|
...
config.vm.network "forwarded_port", guest: 80,
host: 8080
...
end
SYNCED FOLDERS
Vagrant.configure("2") do |config|
...
config.vm.synced_folder "src/", "/srv/website"
...
end
PROVISIONING
PROVISIONING
 Provisioners in Vagrant allow you to automatically install
software, alter configurations, and more on the machine
as part of the vagrant up process.
 Provisioners
 File
 Shell
 Ansible
 CFEngine
 Chef Solo
 Chef Client
 Chef Apply
 Docker
 Puppet Apply
 Puppet Agent
 Salt
SHELL PROVISIONING
Vagrant.configure("2") do |config|
...
config.vm.provision "shell", inline: "echo Hello,
World"
...
end
SHELL PROVISIONING
$script = <<SCRIPT
echo I am provisioning...
date > /etc/vagrant_provisioned_at
SCRIPT
Vagrant.configure("2") do |config|
...
config.vm.provision "shell", inline: $script
...
end
SHELL PROVISIONING
Vagrant.configure("2") do |config|
...
config.vm.provision "shell", path: "script.sh"
...
end
SHELL PROVISIONING
Vagrant.configure("2") do |config|
...
config.vm.provision "shell" do |s|
s.inline = "echo $1"
s.args = "'hello, world!'"
end
...
end
PLUGINS
VAGRANT-VBOX-SNAPSHOT
 Setup
 vagrant plugin install vagrant-winnfsd
 vagrant plugin install vagrant-vbox-snapshot
 Usage
 vagrant snapshot <command> [<args>]
VAGRANT-VBOX-SNAPSHOT
 Sub Commands
 back
 vagrant snapshot back [vm-name]
 delete
 vagrant snapshot delete [vm-name] <SNAPSHOT_NAME>
 go
 vagrant snapshot go [vm-name] <SNAPSHOT_NAME>
 list
 vagrant snapshot list
 take
 vagrant snapshot take [vm-name] <SNAPSHOT_NAME>
VAGRANT-VBOX-SNAPSHOT
 Example
 Vagrant snapshot take “init”
 Vagrant snapshot list
 Vagrant snapshot go “init”
 Vagrant snapshot delete “init”
VAGRANT-VBOX-SNAPSHOT
VAGRANT-VBOX-SNAPSHOT
VAGRANT-VBOX-SNAPSHOT
VAGRANT-PROXYCONF
 Setup
 vagrant plugin install vagrant-proxyconf
VAGRANT-PROXYCONF
...
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = "http://proxy.xuenn.com:3128/"
config.proxy.https = "https://proxy.xuenn.com:3128/"
config.proxy.no_proxy = "localhost,127.0.0.1"
end
...
...
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = "http://username:password@proxy.xuenn.com:3128/"
config.proxy.https =
"https://username:password@proxy.xuenn.com:3128/"
config.proxy.no_proxy = "localhost,127.0.0.1"
end
...
REFERENCE
50
REFERENCE
 Vagrant
 https://www.vagrantup.com/
 Atlas by HashiCorp
 https://atlas.hashicorp.com/
 Vagrant - Create and configure lightweight, reproducible,
and portable development environments - Level Up- 點
部落
 http://www.dotblogs.com.tw/larrynung/archive/2013/06/14/1055
17.aspx
 Vagrant - VBox Snapshot - Level Up
 http://larrynung.github.io/2015/10/19/vagrant-vbox-snapshot/
51
REFERENCE
 Vagrant - Creating a new box from an existing VM -
Level Up
 http://larrynung.github.io/2015/10/17/vagrant-creating-a-new-
box-from-an-existing-vm/
 Vagrant - SSH in windows - Level Up
 http://larrynung.github.io/2014/10/02/vagrant-ssh-in-windows/
 Vagrant (software) - Wikipedia, the free encyclopedia
 https://en.wikipedia.org/wiki/Vagrant_(software)
52
Q&A
53
QUESTION & ANSWER
54

Vagrant