Post on 22-May-2015
description
Vagrant para automatizar entornos DEV/PROVagrant + Chef Solo + [VirtualBox, vSphere]
@javier_jeronimo
Objetivos
● Entorno desarrollo = entorno producción○ Mismo SO○ Mismas herramientas, bibliotecas, versiones...
● Automatizar entornos○ Poder destruir y re-generar desde cero○ Sólo esto asegura DEV=PRO
● Control de versiones para todo● Gestión de dependencias automática
Vagrant
Gestión de máquinas virtuales desde línea de comandos:● vagrant up● vagrant halt● vagrant sshvagrant up => un sólo comando por primera vez y la máquina estará lista y en ejecución
Vagrant - Conceptos
1. Definición
Vagrant - Conceptos (1)
Definición de la máquina virtual● Carpeta conteniendo un Vagrantfile
● ID de la “caja” base (box). Ej: precise64● URL de la caja (descarga y cache local)
○ ¡Cuidado con cajas con mismo ID!● Configuración VM: IP, puertos, etc● Sintaxis del fichero: Ruby DSL
Vagrant - Conceptos (1)Vagrant::Config.run do |config| # v1 # All Vagrant configuration is done here. The most common configuration # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com.
# Boot with a GUI so you can see the screen. (Default is headless) # config.vm.boot_mode = :gui
# Assign this VM to a bridged network, allowing you to connect directly to a # network using the host's network device. This makes the VM appear as another # physical device on your network. # config.vm.network :bridged
# Forward a port from the guest to the host, which allows for outside # computers to access the VM, whereas host only networking does not.
# config.vm.forward_port 80, 8080
[...]
Vagrant - Conceptos
2. Proveedor
Vagrant - Conceptos (2)
Proveedor (provider) de la máquina:● ¿Qué es? => Quien finalmente la ejecutaProveedores:● VirtualBox (incluido en Vagrant)● VMWare, de pago (Workstation, Fusion)● Otros mediante plugins: AWS, vSphere, etc.
Vagrant - Conceptos
3. Aprovisionador
Vagrant - Conceptos (3)
Aprovisionador (provisioner):● Prepara la máquina: instala paquetes,
configura usuarios, etc.● Varios disponibles:
○ Shell script○ Puppet○ Chef Solo○ ...
Vagrant - Plugins
● Proveedores. Ej: Añadir soporte para AWS, vSphere, OpenStack, Parallels, ...
● Aprovisionadores. Ej:○ Chef: gestionar dependencias con Berkshelf o
Librarian, actualizar con OmniBus, …○ Puppet: gestionar dependencias con Librarian○ Otros: añadir soporte para Fabric, ...
● Otros. Ej: exec, screenshot, ...
Vagrant - Gestión configuración
Vagrantfile
Berksfile ./cookbooks/*
./databags/*
./roles/*
URL-de-la-caja
Gestión de configuración de las recetas Chef
Recetas a ejecutar + parámetros JSON
Caja base: ID + URL
ProveedorVirtualBox (instalación local)
vSphere (servidor)
1
2
3
Vagrant - Diferentes entornos
Desarrollo:● VirtualBox● Detalles:
○ Redes host-guest, guest-guest
○ DNS en /etc/hosts● Entorno aislado en
ordenador
Producción:● VMware vSphere● Detalles:
○ Red virtualizada en CPD
○ DNS por servidor● Entorno CPD
virtualizado
Vagrant - Gestión configuraciónRepositorio:
● cookbooks/● databags/● roles/● boxes/
○ vsphere.box <== (caja vacía: sólo metadatos provider)○ precise64_virtualbox.box <== (VirtualBox VM: disco duro con datos, definición...)
● production/○ server01/
■ Vagrantfile <== (provider=vSphere, box=vsphere.box)■ Berksfile <== (gestión de dependencias Chef)
● development/○ server01/
■ Vagrantfile <== (provider=VirtualBox, box=precise64_virtualbox.box)■ Berksfile <== (gestión de dependencias Chef)
● Gemfile <== (gestión de dependencias Ruby)● plugins.json <== (gestión de dependencias: plugins Vagrant)
Vagrant - Entorno desarrollo
OrdenadorIngeniero SW
VirtualBox: VMs
web.example.comsql.example.comtasks.example.com...
Red virtual Red virtual Red virtual Red virtual
Vagrant - Entorno desarrollo
Vagrant 1 Descarga y cache local de la caja: *_virtualbox
1
Virtualbox
2 Creación de la máquina virtual
4VM Boot + configuración básica: IP, puertos, carpetas compartidas, ...
2
3
Chef-Solo 6 Instalación de la máquina virtual: recetas, datos...
4
CLI
3Plugin: Berkshelf
5
5Plugin: Chef OmniBus installer
6
CLIincluido en vagrant
Vagrant - Entorno producción
OrdenadorIngeniero SW
web.example.comsql.example.comtasks.example.com...
Servidor vSphere ESXi
Vagrant - Entorno producción
2 Creación: template + customization spec
2vSphere
3 Creación de la máquina virtual: template + spec
5VM Boot + configuración básica: IP, puertos, carpetas compartidas, ...
3
4
Chef-Solo 7 Instalación de la máquina virtual: recetas, datos...
5
API4Plugin: Berkshelf
6
6Plugin: Chef OmniBus installer
7
API
vSphere
1 Descarga de una máquina VMWare
1
plugin vagrant
Objetivos
● Entorno desarrollo = entorno producción○ Distinta máquina: IPs, VirtualBox vs vSphere...○ Mismas recetas Chef: gestión de configuración
● Automatizar entornos○ vagrant up / vagrant provision / vagrant destroy
● Control de versiones para todo● Gestión de dependencias automática
○ Bundler (Gemfile), Berkshelf (Berksfile + cookbooks/*/metadata.rb)
ReferenciasVagrant - Plugins: https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-PluginsVagrant - Cajas: http://www.vagrantbox.es/Berkshelf: http://berkshelf.comvSphere - Templates: http://goo.gl/H8jdxQvSphere - Customization specs: http://goo.gl/OUVcTo