vagrant and centos 7
DESCRIPTION
An introduction to Vagrant, using CentOS 7, given at CentOS Dojo Paris 2014 (2014/08/25).TRANSCRIPT
...
Vagrant and CentOS 7Vagrant and CentOS 7Julien Pivotto
CentOS Dojo, ParisAugust 25, 2014
..
whoamiwhoamiJulien PivottoJulien Pivotto
• System administrator at inuits.eu
• CentOS user since CentOS 5.5• DevOps believer• Open-source defender since 2004• roidelapluie on twitter/github
..
• Tool to build development environments• Easy to use, easy to configure• Extensible via plugins• Supports config management utilities
▶ Chef▶ Puppet▶ Cfengine▶ Docker▶ …
..
A bit of contextA bit of context
• Born in 2010 as a ruby gem• Written by Mitchell Hashimoto (@mitchellh)• Used to be a wrapper around VirtualBox
..
Working without VagrantWorking without Vagrant
..
Working without VagrantWorking without Vagrant
• Hard to rebuild, reproduce• No isolation• Not the same OS as in production• What if multiple versions of mysqld/java/…?
..
Working with VagrantWorking with Vagrant
..
Fixed problemsFixed problems
• Easy to rebuild, reproduce• No more "Works on my machine"• Use the same OS as the production OS• Use multiple VM's if needed• Desktop OS is not full of useless config
..
Development environmentDevelopment environment
• One or multiple virtual machine, container, …• Provisionned (puppet, chef, ansible, script…)• Any operating system• A lot of providers supported
▶ Virtualbox▶ Docker▶ AWS (plugin)▶ KVM/Qemu (plugin)▶ LXC (plugin)▶ Also closed source VMWare, Hyper-V
..
A Vagrant base boxA Vagrant base box
• A VM or an image or a Dockerfile• SSH access if virtual machine• SSH user for Vagrant• Optional provisioning systems
..
vagrant box lifecyclevagrant box lifecycle
..
vagrant box lifecyclevagrant box lifecycle
..
vagrant box lifecyclevagrant box lifecycle
..
Getting startedGetting started
• Install Virtualbox and Vagrant• Import your first box
▶ centos.org▶ vagrantcloud.com▶ vagrantbox.es
...
Importing a Vagrant base boxImporting a Vagrant base box
...
Importing a Vagrant base boxImporting a Vagrant base box
..
vagrant box add <box url>vagrant box add <box url>
• Fetches a base box• Takes an URL, a json file or a tarball asparameter
• Adds it to the available base boxes• Now we can use the box at will!
...
Creating a VagrantfileCreating a Vagrantfile
...
Creating a VagrantfileCreating a Vagrantfile
..
vagrant init <box name>vagrant init <box name>Creates a simple VagrantfileCreates a simple Vagrantfile
• The Vagrantfile is the configuration file• It contains the definition of the environment• It is written in ruby
..
Simple VagrantfileSimple Vagrantfile
VAGRANTFILE_API_VERSION = "2"Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "vStone/centos−7.x−puppet.3.x"end
..
Battleship readyBattleship ready
..
Vagrant commandsVagrant commands
• vagrant box add <box url>: fetches a box• vagrant init <box name>: creates Vagrantfile
...
Booting the VMBooting the VM
...
Booting the VMBooting the VM
..
vagrant upvagrant up
• Creates a VM in Virtualbox• Prepares it: setting name, network, portforwarding
• Once booted: sets the hostname• On the first run, provisions the VM if needed
..
ProvisioningProvisioning
• Altering the box• Changing configuration• Running shell scripts• Running Puppet, Chef, Ansible…
..
Vagrantfile with provisioningVagrantfile with provisioning
VAGRANTFILE_API_VERSION = "2"Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "vStone/centos−7.x−puppet.3.x"config.vm.provision "shell", inline: "yum install −y
httpd"end
...
Provisioning the VMProvisioning the VM
...
Provisioning the VMProvisioning the VM
..
Vagrant commandsVagrant commands
• vagrant box add <box url>: fetches a box• vagrant init <box name>: creates Vagrantfile• vagrant up: starts/creates the vm• vagrant provision: run cfgmgmt, scripts
..
ProvisionersProvisioners
• Shell• Puppet• Chef• Ansible• $YOUR_PLUGIN
...
I am doneI am done
...
I am doneI am done
..
vagrant destroyvagrant destroy
• Allows you to delete the vm• Frees disk space• Ready for a clean vagrant up
...
vagrant up (again)vagrant up (again)
...
vagrant up (again)vagrant up (again)
..
vagrant up (cont)vagrant up (cont)
• At first boot, provision the VM if needed• For next boots, force with --provision
...
SSHSSH
...
SSHSSH
...
I am done (for today)I am done (for today)
...
I am done (for today)I am done (for today)
..
vagrant haltvagrant halt
• Halts the VM• No more than a shutdown• Start again with vagrant up
..
Vagrant commandsVagrant commands
• vagrant box add <box url>: fetches a box• vagrant init <box name>: creates Vagrantfile• vagrant up: starts/creates the vm• vagrant provision: run cfgmgmt, scripts• vagrant destroy: deletes the vm• vagrant halt: stops the vm• vagrant ssh: ssh the virtual machine
..
Vagrant 101Vagrant 101
..
Puppet provisioningPuppet provisioning
VAGRANTFILE_API_VERSION = "2"Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "vStone/centos−7.x−puppet.3.x"config.vm.provision "shell", inline: "yum install −q −
y bind−utils"config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "manifests"puppet.module_path = "modules"puppet.manifest_file = "site.pp"
endend
...
Puppet provisioningPuppet provisioning
...
Puppet provisioningPuppet provisioning
..
Puppet provisioningPuppet provisioning
• Runs puppet code over a VM• Tip: use the same code as in prod• Allow sysadmins to test Puppet code
..
Port forwardingPort forwarding
VAGRANTFILE_API_VERSION = "2"Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "vStone/centos−7.x−puppet.3.x"config.vm.network "forwarded_port", guest: 80, host:
8080config.vm.provision "shell", inline: "yum install −q −
y bind−utils"config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "manifests"puppet.module_path = "modules"puppet.manifest_file = "site.pp"
endend
...
Enable port forwardingEnable port forwarding
...
Enable port forwardingEnable port forwarding
..
Multiple VM'sMultiple VM'sVAGRANTFILE_API_VERSION = "2"Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "vStone/centos−7.x−puppet.3.x"config.vm.network "forwarded_port", guest: 80, host:
8080config.vm.provision "shell", inline: "yum install −q −
y bind−utils"config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "manifests"puppet.module_path = "modules"puppet.manifest_file = "site.pp"
endconfig.vm.define "web1" do |webvm|
webvm.vm.Network "forwarded_port", guest: 80, host:8080
endconfig.vm.define "web2" do |webvm|
webvm.vm.Network "forwarded_port", guest: 80, host:8081
end
end
...
Start multiple VM'sStart multiple VM's
...
Start multiple VM'sStart multiple VM's
..
Multiple VM'sMultiple VM's
• Multiple VM's defined in one file• Vagrant commands can take the name ofthe vm as argument
• Remember: a vagrant file is a ruby file (thinkloops, hashes, …)
..
NetworkingNetworking
• Multiple networking possibilites• Port forwarding• Internal network• Public network (bridge)• Depending on provider
..
Networking and CentOS 7Networking and CentOS 7
• Not yet supported OOTB• But plugins are there!• vagrant plugin install vagrant-centos7_fix
..
Vagrant commandsVagrant commands
• vagrant box add <box url>: fetches a box• vagrant init <box name>: creates Vagrantfile• vagrant up: starts/creates the vm• vagrant provision: run cfgmgmt, scripts• vagrant destroy: deletes the vm• vagrant halt: stops the vm• vagrant ssh: ssh the virtual machine• vagrant reload: vagrant halt && vagrant up• vagrant status: gets the status of the vm
..
File sharingFile sharing
• Vagrant allows you to share files betweenhost and guest
• Protocol depends on privider: NFS, rsync,vbox-addons,…
• By default, the Vagrantfile directory ismounted on /vagrant
..
Creating Vagrant base boxesCreating Vagrant base boxes
• Re-package your used boxes• Veewee: creates vagrant boxes (and more)• Packer: creates vagrant boxes (and more)
..
ConclusionConclusionVagrantVagrant
• Vagrant is a tool for everyone• Have a clean environment in minutes• Safely experience change• Test on multiple platforms
..
ConclusionConclusionVagrant plays nicely with:Vagrant plays nicely with:
• Jenkins (plugins available)• Puppet (project beaker)• Any OS• A lot of cloud providers
..
ConclusionConclusionVagrant commandsVagrant commands
• vagrant up• vagrant provision• vagrant destroy
..
ConclusionConclusionGoing furtherGoing further
• Read Vagrantfile's comments• vagrantup.com
..
Thank youThank you
Any question?
..
ContactContact
Julien [email protected]@roidelapluie
INUITS bvbaBelgium+32 473 441 636https://inuits.eu