infrastructure as code

25
Infrastructure Infrastructure as Code as Code

Upload: angel-nunez-salazar

Post on 13-Apr-2017

162 views

Category:

Software


0 download

TRANSCRIPT

InfrastructureInfrastructureas Codeas Code

Angel NúñezAngel Núñez@snahider@snahider

Agile Developer,Agile Developer,Consultant & TrainerConsultant & Trainer

IT Ops es un trabajoIT Ops es un trabajocomplicadocomplicado

Snowflake ServersSnowflake Servers

ProblemasProblemas

Difícil replicar un nuevo servidor conlas mismas funciones.Difícil de escalar.Desfases entre ambientes.Muy frágiles y cambios con efectossecundarios.Baja confianza al realizar cambios.Sin versionamiento y seguimiento alos cambios.

¿Qué es¿Qué esInfrastructure as Code?Infrastructure as Code?

Es una práctica donde se describe y maneja lainfraestructura de la misma manera que el código.

Utilizando un lenguaje de alto nivel(DSL para infraestructura).

Utilizando buenas prácticas de desarrollo de software(ejm: subir los cambios a un repositorio).

HerramientasHerramientas

PuppetPuppet ChefChef package { 'apache2': ensure => installed, }

service { 'apache2': ensure => running, require => Package['apache2'], }

file { '/var/www/html/index.html': content => '<html>hello world</html>', owner => 'root', mode => '640', ensure => present, }

package 'apache2' do action :install end

service 'apache2' do action [:enable, :start] end

file '/var/www/html/index.html' do content '<html>hello world</html>' owner 'root' mode '640' action :create end

Características: Abstracción e Idempotencia

¿Cómo es el código¿Cómo es el códigode infraestructura?de infraestructura?

BeneficiosBeneficios(Utilizar un script automatizado(Utilizar un script automatizado

idempotente)idempotente)

Crear una nueva máquina automatizadamente desde 0.

Asegurar que los ambientes son consistentes.

Agregar un cambio y que se actualice en todos los servidores.

Generar el ambiente de trabajo al equipo de desarrollo.

BeneficiosBeneficios(Utilizar código mediante una DSL de(Utilizar código mediante una DSL de

infraestructura)infraestructura)

Probar todos los cambios.

Versionado y seguimiento de los cambios.

Integración y entrega continua de la infraestructura.

Infraestructura auto-documentada.

Herencia, composición, reusabilidad, encapsulamiento, etc.

DemostraciónDemostración"Instalando y Configurando"Instalando y Configurando

Apache"Apache"

Probando Probando Infrastructure CodeInfrastructure Code

Unit TestUnit Test

Probar unitariamente elcódigo sin provisionar (alterar)

un nodo real.

Integration TestsIntegration Tests

Verificar que el códigoprovisiona un nodo real de la

manera esperada.

Tipos de PruebasTipos de Pruebas

IntegrationIntegrationTestingTesting

Desafíos al RealizarDesafíos al RealizarIntegration TestingIntegration Testing

Crear ambientes de pruebasde manera fácil y repetible.Interrogar el estado real del servidor.Un Test Harness que combine lo anterior.

RSpec-PuppetRSpec-Puppethttps://github.com/rodjek/rspec-puppet

VagrantVagranthttps://www.vagrantup.com/

ServerspecServerspechttp://serverspec.org/

BeakerBeakerhttps://github.com/puppetlabs/beaker

PruebaPrueba# spec/acceptance/jenkins_spec.rb

describe 'jenkins class' do it 'should work with no errors' do pp = "include jenkins" expect(apply_manifest(pp).exit_code).to eq(0) end #Serverspec describe service('jenkins') do it { should be_enabled } endend

# spec/acceptance/nodesets/default.yml

HOSTS: ubuntu-1404-x86: roles: - masterless platform: ubuntu-1404-x86_64 hypervisor: vagrant box: ubuntu14.04-x86

Ambiente de PruebaAmbiente de Prueba

Integration TestsIntegration Tests

Configuración delConfiguración delAmbienteAmbiente

# spec/spec_helper_acceptance.rb

RSpec.configure do |c| # Configure all nodes in nodeset c.before :suite do hosts.each do |host| # Install this module copy_module_to(host, :source => module_root, :module_name => 'jenkins') # copies all the module dependencies rsync_to(host ,fixture_modules, '/etc/puppet/modules/') end endend

DemostraciónDemostración

"Agregando Pruebas al"Agregando Pruebas almódulo de Apache" módulo de Apache"

Porqué CD y DevopsPorqué CD y Devopsnecesitannecesitan

Infrastructure as CodeInfrastructure as Code

Infrastructure as Code es un habilitador:

Permite agregar la infraestructura al pipeline deContinuous Delivery.Permite que Operaciones pueda utilizar prácticaságiles para gestionar la infraestructura.Rompe barreras entre Dev y OPS.

PreguntasPreguntas

ReferenciasReferenciasPresentación (código y slides):https://github.com/snahider/test-driven-infrastructure