This document provides an introduction and overview of using Vagrant to manage virtual machines.
It begins with a brief explanation of what Vagrant is and its basic features. It then demonstrates simple commands to install Vagrant, add a base box, initialize a Vagrantfile configuration, and boot a virtual machine.
The document progresses to more advanced Vagrantfile configuration topics like specifying base boxes, network configuration, shared folders, and defining multiple virtual machines. It also introduces using Puppet configuration management with Vagrant to provision virtual machines in a repeatable way.
8. Step 2 :: Add Base Box
$ vagrant box add base
http://files.vagrantup.com/precise32.box
…….
[vagrant] Downloading withVagrant::Downloaders::File...
[vagrant] Copying box to temporary location...
[vagrant] Extracting box...
[vagrant]Verifying box...
[vagrant] Cleaning up downloaded box...
9. Step 2.1 :: Where is my box ?
o http://www.vagrantbox.es/
10. Step 3 :: Configuration
$ vagrant init
…..
A `Vagrantfile` has been placed in this directory.You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in theVagrantfile as well as documentation on
`vagrantup.com` for more information on usingVagrant.
12. Step 4 :: Boot
$ vagrant up
….
[default] Importing base box 'base'...
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Fixed port collision for 22 => 2222. Now on port 2200.
[default] Forwarding ports...
[default] -- 22 => 2200 (adapter 1)
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] BootingVM...
[default] Waiting forVM to boot.This can take a few minutes.
22. Multiple VM in Stack
o Web Server
o Application Server
o Database Server
o Caching Server
o Messaging Server
23. Web Server and DB Server
Vagrant::Config.run do |config|
config.vm.define :web do |web_config|
web_config.vm.host_name = "web01.internal"
web_config.vm.network :hostonly, "192.168.0.100"
end
config.vm.define :db do |db_config|
db_config.vm.host_name = "db01.internal"
db_config.vm.network :hostonly, "192.168.0.101"
end
end
25. DEMO MORE
o Web Server
o web-01.vagrant.internal 33.33.33.11
o web-02.vagrant.internal 33.33.33.12
o DB Server
o db-01.vagrant.internal 33.33.33.21
27. Create Servers
nodes.each do |prefix, (count, ip_start)|
count.times do |i|
hostname = "%s-%02d" % [prefix, (i+1)]
config.vm.define "#{hostname}" do |box|
box.vm.host_name = "#{hostname}.vagrant.internal"
box.vm.network :hostonly, "33.33.33.#{ip_start+i}“
end
end
end
29. Vagrant with Puppet
o https://puppetlabs.com
o Configuration management with Code
o Ruby
o Repeatable
30. Demo :: Install all in one
o Manage package with Puppet
o Java
o Apache Tomcat
o Redis
o RabbitMQ
https://github.com/up1/geeky_devops
demo-puppet
31. Structure of Puppet
o puppet
o manifests/default.pp
o modules
o java
o manifests/init.pp
o tomcat
o manifests/init.pp
o redis
o manifests/init.pp
o rabbitMQ
o manifests/init.pp
Starting point
32. Vagrantfile
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "default.pp"
puppet.module_path = "puppet/modules"
end
Vagrant provision
Starting point
34. Structure of Puppet
o puppet
o manifests/default.pp
o modules
o java
o manifests/init.pp
o tomcat
o manifests/init.pp
o redis
o manifests/init.pp
o rabbitMQ
o manifests/init.pp
Starting point
each module
40. More Demo
o https://github.com/up1/geeky_devops
o demo-multi-puppet
box.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "#{prefix}.pp"
puppet.module_path = "puppet/modules"
end