Vagrant is an excellent tool for quickly setup a development environment in a reproducible manner. However it is also a DecOps tool. In this talk the idea is to introduce audience how they can use Vagrant for DevOps
2. DevOps
What is it?
• It is a culture.
• Filling the gap between developer and operations.
3. DevOps
It aims at establishing a culture and environment
where building, testing, and releasing software, can
happen rapidly, frequently, and more reliably.
-Wikipedia
It means:
• Use right tools for automation, continuous
integration and achieve continuous delivery.
4. Vagrant
• Create and configure lightweight, reproducible,
and portable development environments.
• A higher-level wrapper around virtualization
software such as VirtualBox, VMware, KVM.
• Also wrapper around configuration management
software such as Ansible, Chef, Salt, and Puppet.
• Public clouds e.g. AWS, DigitalOcean can be
providers too.
6. Vagrant :Quick Start
• mkdir centos; cd centos
• $ vagrant init centos/7
• $ vagrant up
OR
• $ vagrant up --provider <PROVIDER>
• $vagrant ssh
* These steps going to stay the same irrespective of OS and providers.
8. Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = “centos/7"
# config.vm.network "forwarded_port", guest: 80, host: 8080
# config.vm.network "private_network", ip: “192.168.33.10"
# config.vm.network "public_network"
# config.vm.synced_folder "../data", "/vagrant_data"
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize CPU
# v.cpus = 2
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# config.vm.provision "shell", inline: <<-SHELL
# sudo yum update -y
# sudo yum install -y docker
# SHELL
end
9. Multi-machine Environment
• Setup multiple machines with just one “$ vagrant up”
command.
Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: "echo Hello"
config.vm.define "web" do |web|
web.vm.box = "apache"
end
config.vm.define "db" do |db|
db.vm.box = "mysql"
end
end
10. Using Configuration
management Software
• We have Vagrant provisioners for Puppet, Chef, Ansible, CFEngine etc
Vagrant.configure("2") do |config|
# Run Ansible from the Host
config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
end
end
11. Debugging
• VAGRANT_LOG environment variable for the desired log level name.
• Log levels are : debug (loud), info (normal), warn (quiet), and error (very
quiet)
$ VAGRANT_LOG=info vagrant up
OR
$ set VAGRANT_LOG=info
$ vagrant up
OR
$ vagrant up --info
12. Vagrant Plugins
• Add additional features or change default
behaviour.
• It is a Ruby gem. Vagrant is written in Ruby.
• List : https://github.com/mitchellh/vagrant/wiki/
Available-Vagrant-Plugins
13. Using DigitalOcean as a
Provider
• Install Vagrant plugin vagrant-digitalocean
• https://github.com/devopsgroup-io/vagrant-
digitalocean
• Demo
14. Vagrantbox
A Vagrantbox is a tarred, gzip file containing the following:
• Vagrantfile
• The information from this will be merged into your Vagrantfile that is created
when you run vagrant init boxname in a folder.
• box-disk.vmd (For Virtualbox)
• The box-disk.vmdk is the virtual machine image.
• box.of
• The box.ovf defines the virtual hardware for the box.
• metadata.son
• The metadata.json tells vagrant what provider the box works with.
15. Tools To Create Vagrantbox
• You can use tools like packer.io, imagefactory etc.
• You can build a Vagrantbox manually
• Or use “vagrant package” command for Virtualbox.
• Modify base boxes and reuse them.
• Also there is vagrant-mutate
• https://github.com/sciurus/vagrant-mutate
16. DevOps Workflow
• Use same configuration management code as
operations team in Vagrantfile.
• More automation means, more chance of parity
between development, testing and operations.
• Create a environment where developers and QA
can contribute to the automation and configuration
management code.
17. Future
• Otto
• The next generation tool from Hashicorp which uses Vagrant
and other ecosystem tools.
• But It is specially designed for micro services.
• Knows how to install and configure service dependencies for
development and deployment.
• otto dev : will create the development environment.
• otto infra, otto build, and otto deploy : will launches a complete
infrastructure, builds your application, and deploys it