Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

20
Vagrant para automatizar entornos DEV/PRO Vagrant + Chef Solo + [VirtualBox, vSphere] @javier_jeronimo

description

Breve introducción a Vagrant y definición de la gestión de configuración de los entornos desarrollo y producción, y del proceso de automatización de las infraestructuras localmente en VirtualBox y en un servidor VMware vSphere.

Transcript of Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

Page 1: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

Vagrant para automatizar entornos DEV/PROVagrant + Chef Solo + [VirtualBox, vSphere]

@javier_jeronimo

Page 2: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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

Page 3: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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

Page 4: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

Vagrant - Conceptos

1. Definición

Page 5: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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

Page 6: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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

[...]

Page 7: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

Vagrant - Conceptos

2. Proveedor

Page 8: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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.

Page 9: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

Vagrant - Conceptos

3. Aprovisionador

Page 10: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

Vagrant - Conceptos (3)

Aprovisionador (provisioner):● Prepara la máquina: instala paquetes,

configura usuarios, etc.● Varios disponibles:

○ Shell script○ Puppet○ Chef Solo○ ...

Page 11: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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, ...

Page 12: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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

Page 13: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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

Page 14: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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)

Page 15: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

Vagrant - Entorno desarrollo

OrdenadorIngeniero SW

VirtualBox: VMs

web.example.comsql.example.comtasks.example.com...

Red virtual Red virtual Red virtual Red virtual

Page 16: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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

Page 17: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

Vagrant - Entorno producción

OrdenadorIngeniero SW

web.example.comsql.example.comtasks.example.com...

Servidor vSphere ESXi

Page 18: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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

Page 19: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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)

Page 20: Vagrant para automatizar entornos DEV/PRO: VirtualBox y vSphere

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