vagrant and centos 7

67
. . Vagrant and CentOS 7 Vagrant and CentOS 7 Julien Pivotto CentOS Dojo, Paris August 25, 2014

Upload: julien-pivotto

Post on 22-Jan-2015

4.250 views

Category:

Technology


8 download

DESCRIPTION

An introduction to Vagrant, using CentOS 7, given at CentOS Dojo Paris 2014 (2014/08/25).

TRANSCRIPT

Page 1: Vagrant and CentOS 7

...

Vagrant and CentOS 7Vagrant and CentOS 7Julien Pivotto

CentOS Dojo, ParisAugust 25, 2014

Page 2: Vagrant and CentOS 7

..

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

Page 3: Vagrant and CentOS 7

..

• Tool to build development environments• Easy to use, easy to configure• Extensible via plugins• Supports config management utilities

▶ Chef▶ Puppet▶ Cfengine▶ Docker▶ …

Page 4: Vagrant and CentOS 7

..

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

Page 5: Vagrant and CentOS 7

..

Working without VagrantWorking without Vagrant

Page 6: Vagrant and CentOS 7

..

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/…?

Page 7: Vagrant and CentOS 7

..

Working with VagrantWorking with Vagrant

Page 8: Vagrant and CentOS 7

..

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

Page 9: Vagrant and CentOS 7

..

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

Page 10: Vagrant and CentOS 7

..

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

Page 11: Vagrant and CentOS 7

..

vagrant box lifecyclevagrant box lifecycle

Page 12: Vagrant and CentOS 7

..

vagrant box lifecyclevagrant box lifecycle

Page 13: Vagrant and CentOS 7

..

vagrant box lifecyclevagrant box lifecycle

Page 14: Vagrant and CentOS 7

..

Getting startedGetting started

• Install Virtualbox and Vagrant• Import your first box

▶ centos.org▶ vagrantcloud.com▶ vagrantbox.es

Page 15: Vagrant and CentOS 7

...

Importing a Vagrant base boxImporting a Vagrant base box

Page 16: Vagrant and CentOS 7

...

Importing a Vagrant base boxImporting a Vagrant base box

Page 17: Vagrant and CentOS 7

..

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!

Page 18: Vagrant and CentOS 7

...

Creating a VagrantfileCreating a Vagrantfile

Page 19: Vagrant and CentOS 7

...

Creating a VagrantfileCreating a Vagrantfile

Page 20: Vagrant and CentOS 7

..

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

Page 21: Vagrant and CentOS 7

..

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

Page 22: Vagrant and CentOS 7

..

Battleship readyBattleship ready

Page 23: Vagrant and CentOS 7

..

Vagrant commandsVagrant commands

• vagrant box add <box url>: fetches a box• vagrant init <box name>: creates Vagrantfile

Page 24: Vagrant and CentOS 7

...

Booting the VMBooting the VM

Page 25: Vagrant and CentOS 7

...

Booting the VMBooting the VM

Page 26: Vagrant and CentOS 7

..

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

Page 27: Vagrant and CentOS 7

..

ProvisioningProvisioning

• Altering the box• Changing configuration• Running shell scripts• Running Puppet, Chef, Ansible…

Page 28: Vagrant and CentOS 7

..

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

Page 29: Vagrant and CentOS 7

...

Provisioning the VMProvisioning the VM

Page 30: Vagrant and CentOS 7

...

Provisioning the VMProvisioning the VM

Page 31: Vagrant and CentOS 7

..

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

Page 32: Vagrant and CentOS 7

..

ProvisionersProvisioners

• Shell• Puppet• Chef• Ansible• $YOUR_PLUGIN

Page 33: Vagrant and CentOS 7

...

I am doneI am done

Page 34: Vagrant and CentOS 7

...

I am doneI am done

Page 35: Vagrant and CentOS 7

..

vagrant destroyvagrant destroy

• Allows you to delete the vm• Frees disk space• Ready for a clean vagrant up

Page 36: Vagrant and CentOS 7

...

vagrant up (again)vagrant up (again)

Page 37: Vagrant and CentOS 7

...

vagrant up (again)vagrant up (again)

Page 38: Vagrant and CentOS 7

..

vagrant up (cont)vagrant up (cont)

• At first boot, provision the VM if needed• For next boots, force with --provision

Page 39: Vagrant and CentOS 7

...

SSHSSH

Page 40: Vagrant and CentOS 7

...

SSHSSH

Page 41: Vagrant and CentOS 7

...

I am done (for today)I am done (for today)

Page 42: Vagrant and CentOS 7

...

I am done (for today)I am done (for today)

Page 43: Vagrant and CentOS 7

..

vagrant haltvagrant halt

• Halts the VM• No more than a shutdown• Start again with vagrant up

Page 44: Vagrant and CentOS 7

..

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

Page 45: Vagrant and CentOS 7

..

Vagrant 101Vagrant 101

Page 46: Vagrant and CentOS 7

..

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

Page 47: Vagrant and CentOS 7

...

Puppet provisioningPuppet provisioning

Page 48: Vagrant and CentOS 7

...

Puppet provisioningPuppet provisioning

Page 49: Vagrant and CentOS 7

..

Puppet provisioningPuppet provisioning

• Runs puppet code over a VM• Tip: use the same code as in prod• Allow sysadmins to test Puppet code

Page 50: Vagrant and CentOS 7

..

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

Page 51: Vagrant and CentOS 7

...

Enable port forwardingEnable port forwarding

Page 52: Vagrant and CentOS 7

...

Enable port forwardingEnable port forwarding

Page 53: Vagrant and CentOS 7

..

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

Page 54: Vagrant and CentOS 7

...

Start multiple VM'sStart multiple VM's

Page 55: Vagrant and CentOS 7

...

Start multiple VM'sStart multiple VM's

Page 56: Vagrant and CentOS 7

..

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, …)

Page 57: Vagrant and CentOS 7

..

NetworkingNetworking

• Multiple networking possibilites• Port forwarding• Internal network• Public network (bridge)• Depending on provider

Page 58: Vagrant and CentOS 7

..

Networking and CentOS 7Networking and CentOS 7

• Not yet supported OOTB• But plugins are there!• vagrant plugin install vagrant-centos7_fix

Page 59: Vagrant and CentOS 7

..

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

Page 60: Vagrant and CentOS 7

..

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

Page 61: Vagrant and CentOS 7

..

Creating Vagrant base boxesCreating Vagrant base boxes

• Re-package your used boxes• Veewee: creates vagrant boxes (and more)• Packer: creates vagrant boxes (and more)

Page 62: Vagrant and CentOS 7

..

ConclusionConclusionVagrantVagrant

• Vagrant is a tool for everyone• Have a clean environment in minutes• Safely experience change• Test on multiple platforms

Page 63: Vagrant and CentOS 7

..

ConclusionConclusionVagrant plays nicely with:Vagrant plays nicely with:

• Jenkins (plugins available)• Puppet (project beaker)• Any OS• A lot of cloud providers

Page 64: Vagrant and CentOS 7

..

ConclusionConclusionVagrant commandsVagrant commands

• vagrant up• vagrant provision• vagrant destroy

Page 65: Vagrant and CentOS 7

..

ConclusionConclusionGoing furtherGoing further

• Read Vagrantfile's comments• vagrantup.com

Page 66: Vagrant and CentOS 7

..

Thank youThank you

Any question?

Page 67: Vagrant and CentOS 7

..

ContactContact

Julien [email protected]@roidelapluie

INUITS bvbaBelgium+32 473 441 636https://inuits.eu