$ vagrant init user/box # Create Vagrantfile for specified base box
$ vagrant up # Create a VM if needed and boot
$ vagrant reload # After every change to Vagrantfile
$ vagrant halt # Turns off the VM
$ vagrant destroy # Deletes the VM
$ vagrant suspend # Suspends the VM
$ vagrant resume # Resumes the VM
$ vagrant ssh # Log in using ssh
$ vagrant status # Status of the VM
Install Vagrant and VirtualBox
(www.vagrantup.com and www.virtualbox.org)
$ vagrant init puppetlabs/ubuntu-14.04-64-puppet
$ vagrant up
$ vagrant ssh
Created with 'vagrant init puppetlabs/ubuntu-14.04-64-puppet'
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "puppetlabs/ubuntu-14.04-64-puppet"
end
Adding networking
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "puppetlabs/ubuntu-14.04-64-puppet"
config.vm.network "private_network", ip: "10.0.1.10"
end
Port forwarding
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "puppetlabs/ubuntu-14.04-64-puppet"
config.vm.network "private_network", ip: "10.0.1.10"
config.vm.network "forwarded_port", guest: 80, host: 8080
end
Shared folders
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "puppetlabs/ubuntu-14.04-64-puppet"
config.vm.network "private_network", ip: "10.0.1.10"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.synced_folder "./", "/vagrant"
end
VM configuration (RAM, CPU, Network)
...
config.vm.box = "puppetlabs/ubuntu-14.04-64-puppet"
config.vm.network "private_network", ip: "10.0.1.10"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.synced_folder "./", "/vagrant"
config.vm.provider :virtualbox do |vb|
# vb.customize ["startvm", :id, "--type", "gui"]
vb.customize ["modifyvm", :id, "--memory", "512"]
vb.customize ["modifyvm", :id, "--cpus", "1"]
vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
vb.customize ["modifyvm", :id, "--audio", "none"]
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
end
end
Provisioner setup
...
vb.customize ["modifyvm", :id, "--audio", "none"]
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
end
config.vm.provision "puppet" do |puppet|
#puppet.manifests_path = "puppet/manifests"
#puppet.module_path = "puppet/modules"
#puppet.manifest_file = "site.pp"
puppet.environment_path = "puppet/environments"
puppet.environment = "vagrant"
end
end
<TYPE> { '<TITLE>':
<ATTRIBUTE> => <VALUE>,
}
file { 'vagrant-vhost.conf':
path => "/etc/apache2/sites-available/vagrant-vhost.conf",
ensure => file,
source => "puppet:///modules/apache/vagrant-vhost.conf",
require => Package['apache2'],
notify => Service['apache2'],
owner => 'root',
mode => '0644',
}
package { 'apache2':
ensure => installed,
before => File['vagrant-vhost.conf'],
}
service {'apache2':
ensure => running,
subscribe => File['vagrant-vhost.conf'],
}
Package['ntp'] -> File['/etc/ntp.conf'] ~> Service['ntpd']
class apache2 (String $version = 'latest') {
file { 'vagrant-vhost.conf':
path => "/etc/apache2/sites-available/vagrant-vhost.conf",
ensure => file,
source => "puppet:///modules/apache/vagrant-vhost.conf",
require => Package['apache2'],
notify => Service['apache2'],
owner => 'root',
mode => '0644',
}
package { 'apache2':
ensure => $version,
before => File['vagrant-vhost.conf'],
}
service {'apache2':
ensure => running,
subscribe => File['vagrant-vhost.conf'],
}
}
$ tree --prune puppet
puppet
└── environments
└── vagrant
├── manifests
│ └── site.pp
└── modules
├── apache
│ ├── files
│ │ └── vagrant-vhost.conf
│ └── manifests
│ └── init.pp
├── mysql
│ └── manifests
│ └── init.pp
└── php
├── files
│ └── php.ini
└── manifests
└── init.pp
12 directories, 6 files
.
├── boxes
└── packages
├── linux
│ ├── packer
│ ├── vagrant
│ └── virtualbox
├── osx
│ ├── packer
│ ├── vagrant
│ └── virtualbox
└── windows
├── packer
├── vagrant
└── virtualbox
$ vagrant box add puppetlabs/ubuntu-14.04-64-puppet puppetlabs-ubuntu-14.04-64-puppet.box
$ git clone https://github.com/lpopov/virtualization-for-developers-workshop.git
$ cd virtualization-for-developers-workshop
$ vagrant up