Infrastructure as Code - ABUG Session

159
Infrastructure as Patrick Debois ABUG-Session

description

An overview of the infrast

Transcript of Infrastructure as Code - ABUG Session

Page 1: Infrastructure as Code - ABUG Session

Infrastructure as

Patrick DeboisABUG-Session

Page 2: Infrastructure as Code - ABUG Session

Blog: http://jedi.be/blog - Twitter : @patrickdebois - #devops

Technical ReviewerMonitoring Chapter Co-Author Veewee / Sahara / Mccloud

Organizer Since 2009 Europe Organizer 2010

Engineer

First Europe Training 2010

Libvirt - Fog

Speaker

Freelance consultant http://github.com/jedi4ever

Page 3: Infrastructure as Code - ABUG Session

CONFIGURATION MANAGEMENT SYSTEMS

http://ansible.cc/

http://opscode.com/chef/

http://cfengine.com/http://palletops.com/http://puppetlabs.com/

Page 4: Infrastructure as Code - ABUG Session

http://www.nerdnirvana.org/wp-content/uploads/2010/12/apology-form.jpg

Chef & Puppet focusedbased on my experience

Page 5: Infrastructure as Code - ABUG Session

SERVICE

FILE2

FILE1PACKAGE

DECLARATIVE LANGUAGE

Page 6: Infrastructure as Code - ABUG Session

“KNOWN STATE”

STATE X STATE YCODE RUN

FILE1SERVICE

FILE2

FILE1PACKAGE

convergence

Page 7: Infrastructure as Code - ABUG Session

“IDEMPOTENCE”

STATE Y STATE YCODE RUN

SERVICE

FILE2

FILE1PACKAGE

SERVICE

FILE2

FILE1PACKAGE

Page 8: Infrastructure as Code - ABUG Session

GIVE ME THE CODE:“LANGUAGE”

Page 9: Infrastructure as Code - ABUG Session

Puppet Chef

class myapache {

package “apache2”

service “apache2”: ensure => “running”, require => Package[“apache2”]

}

package “apache2”

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

EXAMPLE SYNTAX

Page 10: Infrastructure as Code - ABUG Session

TERMINOLOGY

Java Puppet Chef

*.javamanifests

*.pprecipes

*.rb

package module cookbook

Page 11: Infrastructure as Code - ABUG Session

TERMINOLOGY (2)

Java Puppet Chef

singletonparametrized

classesrecipes with attributes

classdefines, classes

definitions, libraries

Page 12: Infrastructure as Code - ABUG Session

SYNTAXPuppet Chef

Limited DSL(by design) DSL + full ruby

Extended by Definitions

Light Weight Resource Providers /

DefinitionsCustom Resource providers

Providers, Light Weight Resource

ProvidersERB & Custom Libraries Libraries

Page 13: Infrastructure as Code - ABUG Session

LOOPING CONSTRUCTS

Puppet Chef

pass array of elementserb template for loops

create_resource (:type, hash)

do while , repeat etc. available through

native ruby

Page 14: Infrastructure as Code - ABUG Session

VARIABLES

Puppet Chef

special syntax$bla = “aa”

string interpolation$bla_string = “${bla}”

native rubybla = “aa”

string interpolationbla_string = #{bla}

Page 15: Infrastructure as Code - ABUG Session

SINGLE CLASSINHERITANCE

Puppet Chef

override via ‘module path’

override via ‘cookbook’ path

+> operator “cookbook” attribute

Page 16: Infrastructure as Code - ABUG Session

Puppet Module Chef Cookbook

files/lib/

README.rdocmanifests/templates/

attributes/definitions/files/libraries/metadata.rbproviders/README.rdocrecipes/resources/templates/

PROJECT STRUCTURE

Page 17: Infrastructure as Code - ABUG Session

EXECUTION MODEL

Puppet Chef

Compile catalog(directed graph

model)Then Execute

Top Down execution

Page 18: Infrastructure as Code - ABUG Session

PLUGINSPuppet Chef

FACES KNIFE PLUGINS

REPORTS REPORT HANDLERS

http://puppetlabs.com/blog/puppet-faces-what-the-heck-are-faces/http://wiki.opscode.com/display/chef/Knife+Plugins

Page 19: Infrastructure as Code - ABUG Session

CODE EDITOR

Page 22: Infrastructure as Code - ABUG Session

http://cloudsmith.github.com/geppetto/https://github.com/cloudsmith/geppetto

GEPPETTO - ECLIPSE IDE

Page 23: Infrastructure as Code - ABUG Session

JETBRAINS RUBYMINE (PUPPET)http://youtrack.jetbrains.com/issue/RUBY-10832

REACTOR8http://beta.r8network.com/

COMING SOON

https://github.com/janschumann/intellij-lang-puppet

Page 24: Infrastructure as Code - ABUG Session

REVERSE ENGINEERING

https://github.com/devstructure/blueprint

Existing Server -> Manifest/Recipes

Page 25: Infrastructure as Code - ABUG Session

CODING STYLE

Page 26: Infrastructure as Code - ABUG Session

Puppet Chef

http://puppet-lint.com/ http://acrmp.github.com/foodcritic/

• Must use two-space soft tabs.• Must not use literal tab characters.• Must not contain trailing white space.• Should not exceed an 80 character line width

An exception has been made for source  =>  'puppet://...' lines as splitting these over multiple lines decreases the readability of the manifests.

• Should align arrows (=>) within blocks of attributes.• ....

• FC001: Use strings in preference to symbols to access node attributes• FC002: Avoid string interpolation where not required• FC003: Check whether you are running with chef server before using server-

specific features• FC004: Use a service resource to start and stop services• FC005: Avoid repetition of resource declarations• FC006: Mode should be quoted or fully specified when setting file

permissions• FC007: Ensure recipe dependencies are reflected in cookbook metadata• FC008: Generated cookbook metadata needs updating• FC009: Resource attribute not recognised• FC010: Invalid search syntax• FC011: Missing README in markdown format• FC012: Use Markdown for README rather than RDoc• FC013: Use file_cache_path rather than hard-coding tmp paths•

http://docs.puppetlabs.com/guides/style_guide.htmlhttps://github.com/ampledata/cookbook-style-guide

Page 28: Infrastructure as Code - ABUG Session

CODE VS CONFIG(THINK “PROFILES”)

http://wiki.opscode.com/display/chef/Data+Bags

http://projects.puppetlabs.com/projects/hierahttps://github.com/crayfishx/hiera-gpg

Page 30: Infrastructure as Code - ABUG Session

PRE-COMMIT CHECKS

Page 31: Infrastructure as Code - ABUG Session

DEPENDENCY MGMT

GitSubmodules

Subtree à la Pom File

Page 32: Infrastructure as Code - ABUG Session

UPSTREAM REPOS

http://forge.puppetlabs.com/http://community.opscode.com/

Page 33: Infrastructure as Code - ABUG Session

Puppet Chef

https://github.com/rodjek/librarian-puppet

https://github.com/applicationsonline/librarian

http://berkshelf.com/

site  "http://community.opscode.com/api/v1"

cookbook  "ntp"cookbook  "timezone",  "0.0.1"

cookbook  "rvm",    :git  =>  "https://github.com/fnichol/chef-­‐rvm",    :ref  =>  "v0.7.1"

cookbook  "cloudera",    :path  =>  "vendor/cookbooks/cloudera-­‐cookbook"

Page 34: Infrastructure as Code - ABUG Session

CHEF METADATA

Page 36: Infrastructure as Code - ABUG Session

http://wham.cloudsmith.com

Online Service

Page 37: Infrastructure as Code - ABUG Session

DEBUGGING

Page 38: Infrastructure as Code - ABUG Session

LOGGING WITH DIFFERENT LEVELS

Info only, no exceptionChef::Log.info('Some  useful  info')

Fatal, raising exceptionChef::Log.fatal('Something  bad')

Page 39: Infrastructure as Code - ABUG Session

REPL - STYLE(READ EVAL PRINT)

http://wiki.opscode.com/display/chef/Shefhttps://github.com/pry/pry

Page 40: Infrastructure as Code - ABUG Session

DEV ENVIRONMENT

Page 41: Infrastructure as Code - ABUG Session

Info & Credits

• Mitchell Hashimoto & John Bender

• http://vagrantup.com

• Based on Virtualbox , Ruby

• OS-Installers (not gem based)

• Runs on Mac OS, Linux, Windows

Page 42: Infrastructure as Code - ABUG Session

http://www.hashicorp.com/

Page 43: Infrastructure as Code - ABUG Session

Vagrant 101

Page 44: Infrastructure as Code - ABUG Session

Step 1 : installation

Page 45: Infrastructure as Code - ABUG Session

The power of CLI

$ vagrant box add base http://files.vagrantup.com/lucid32.box

$ vagrant init$ vagrant up

Page 46: Infrastructure as Code - ABUG Session

Step 2 : base box

$ gem install vagrant

$ vagrant box add base http://files.vagrantup.com/lucid32.box$ vagrant init$ vagrant up

Downloads predefined VM - f.i. Ubuntu 10.04 (Lucid)and registers it as name ‘base’

‘BASE’LUCID

Page 47: Infrastructure as Code - ABUG Session

Step 3 : configuration

$ gem install vagrant$ vagrant box add base http://files.vagrantup.com/lucid32.box

$ vagrant init$ vagrant up

Creates a standard configuration file

Page 48: Infrastructure as Code - ABUG Session

Vagrantfile

Vagrant::Config.run do |config| # Every Vagrant virtual environment requires a box to build off of. config.vm.box = "base"

end

‘BASE’LUCID

Vagrantfile = Project fileLinks our project with the ‘Base’ box

Page 49: Infrastructure as Code - ABUG Session

Step 4 : boot

$ gem install vagrant$ vagrant box add base http://files.vagrantup.com/lucid32.box$ vagrant init

$ vagrant up

Extracts the ‘basebox’Creates a new VM in Virtualbox based on ‘basebox’

Boots the new VM

Page 50: Infrastructure as Code - ABUG Session

Ready to rock SSH

KA-CHING

Page 51: Infrastructure as Code - ABUG Session

I ♥ Vagrant

Page 52: Infrastructure as Code - ABUG Session

Reduces Setup Time

1 2 3 4

No-VMSSH

Ready

Automated

Page 53: Infrastructure as Code - ABUG Session

Simplicity♥

$ gem install vagrant$ vagrant box add base http://files.vagrantup.com/lucid32.box$ vagrant init$ vagrant up

VBoxManage guestcontrol exec[ute] <vmname>|<uuid> <path to program> --username <name> --password <password> [--arguments "<arguments>"] [--environment "<NAME>=<VALUE> [<NAME>=<VALUE>]"] [--flags <flags>] [--timeout <msec>] [--verbose] [--wait-for exit,stdout,stderr||]

copyto|cp <vmname>|<uuid> <source on host> <destination on guest> --username <name> --password <password> [--dryrun] [--follow] [--recursive] [--verbose]

createdir[ectory]|mkdir|md <vmname>|<uuid> <directory to create on guest> --username <name> --password <password> [--parents] [--mode <mode>] [--verbose]

updateadditions <vmname>|<uuid> [--source <guest additions .ISO>] [--verbose]

Page 54: Infrastructure as Code - ABUG Session

Self-Servicing♥

Basebox

“PULL”

Page 55: Infrastructure as Code - ABUG Session

Consistency

Basebox

DEVELOPER1 DEVELOPER2

Page 56: Infrastructure as Code - ABUG Session

Repeatability

Basebox

UP DESTROY UP DESTROY

t1 t2 t3 t4

Page 57: Infrastructure as Code - ABUG Session

Contained

Project 1 Project 2 Project 3

Laptop

Page 58: Infrastructure as Code - ABUG Session

Vagrant 201

Page 59: Infrastructure as Code - ABUG Session

FileSharing

/home/patrick/data

/data

config.vm.share_folder "datastore", "/data", "./data"

Page 60: Infrastructure as Code - ABUG Session

Port Forwarding

80

8080

# 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 "http", 80, 9000 config.vm.forward_port "redis", 6379, 6379 config.vm.forward_port "mysql", 3306, 3306

Page 61: Infrastructure as Code - ABUG Session

Non-Intrusive

Project 1 Project 2 Project 3

Laptop

My Editor My IDE My Browser

Page 62: Infrastructure as Code - ABUG Session

Multi VM Stack

DB DB DB

Project 1 Project 2 Project 3

APP APP APP

WEB WEB WEBconfig.vm.define :web do |web_config| web_config.vm.box = "ubuntu"

...endconfig.vm.define :app do |app_config| app_config.vm.box = "ubuntu"

...endconfig.vm.define :db do |db_config| db_config.vm.box = "ubuntu"

...end

Page 63: Infrastructure as Code - ABUG Session

Vagrant 301

Page 64: Infrastructure as Code - ABUG Session

Basebox

Provision

Just EnoughOperating System

Provisionerchef/puppet/script

+

Cookbooks/Manifests

VM

Page 65: Infrastructure as Code - ABUG Session

Package

Basebox

Just EnoughOperating System

Provisionerchef/puppet/script

+

Cookbooks/Manifests

VM Basebox

Page 66: Infrastructure as Code - ABUG Session

Provision Configconfig.vm.provision :chef_solo do |chef| chef.cookbooks_path = ["chefrepo/cookbooks"]

chef.add_recipe("app_rails")chef.json.merge!({

:apache => { :listen_ports => [ "8080"]})

end ChefSolo

ChefServer

Puppet standalone

Puppet Server

config.vm.provision :puppet do |puppet| puppet.pp_path = "/tmp/vagrant-puppet" puppet.manifests_path = "./manifests" puppet.module_path = "./modules" puppet.manifest_file = "newbox.pp" end

Page 67: Infrastructure as Code - ABUG Session

Veewee

https://github.com/jedi4ever/veewee

Basebox

Just EnoughOperating System

Provisionerchef/puppet/script

ISO

Kickstart/Preseed/Autoyast/

AutoUnattendUbuntu, Debian, Centos,

Fedora, Gentoo, Solaris, Suse, Archlinux,

Windows

Page 68: Infrastructure as Code - ABUG Session

JEOS CREATION

Just Enough Operating System+ Config Management Tool

Your Laptopvirtualization

Virtualbox , FusionKVM, Parallels

Linux & Windows

https://github.com/jedi4ever/veewee/

Centos, Ubuntu, Debian, Solaris, Gentoo, Suse, Oracle Linux, ....

And windows now too!

Page 69: Infrastructure as Code - ABUG Session

SERVICE

FILE2

FILE1PACKAGE

Virtual Machine (1)

Just Enough Operating System+ Config Management Tool

Your Laptopvirtualization

http://vagrantup.com/

Virtualbox + Fusion + EC2

Linux & Windows

Page 70: Infrastructure as Code - ABUG Session

Self-Executable Boxes

• java -jar mygreatbox.jar

http://www.jedi.be/blog/2011/03/31/installable-vagrant-boxes/https://github.com/maestrodev/wanton

“proof of concept”

Page 73: Infrastructure as Code - ABUG Session

CLI Vagrantbox.es

>> vagrant vagrantboxes search centos

3 centos 5.5 http://dl.dropbox.com/u/15307300/vagrant-0.7-centos-64-base.box6 opscode centos 5 http://opscode-vagrant-boxes.s3.amazonaws.com/centos5-gems.box7 opscode ubuntu 10.04 http://opscode-vagrant-boxes.s3.amazonaws.com/ubuntu10.04-gems.box9 puppet centos 5.5 64 http://puppetlabs.s3.amazonaws.com/pub/centos5_64.box10 puppet centos 4 64 http://puppetlabs.s3.amazonaws.com/pub/centos4_64.box21 centos 5.6 32 http://yum.mnxsolutions.com/vagrant/centos_56_32.box

https://github.com/garethr/ruby-vagrantboxes

Page 74: Infrastructure as Code - ABUG Session

http://vmg.slynett.com/

Page 75: Infrastructure as Code - ABUG Session

http://puphpet.com/

Page 76: Infrastructure as Code - ABUG Session

http://vmg.slynett.com/

Page 77: Infrastructure as Code - ABUG Session

Version ControlledBasebox

Just EnoughOperating System

Provisionerchef/puppet/script

ISO

Kickstart/Preseed/Autoyast/

AutoUnattend

VM

Git Repo Git Repo

Cookbooks/Manifests

Vagrantfile

Git Repo

Page 78: Infrastructure as Code - ABUG Session

Complex Setups

VM

Cookbooks/Manifests

Rails Nodejs FlumeHadoop Esper

Mysql HDFSPostgres Java

Page 79: Infrastructure as Code - ABUG Session

Sharing on Github

Kickstart/Preseed/Autoyast/

AutoUnattend

Git Repo Git Repo

Cookbooks/Manifests

Vagrantfile

Git Repo

Veewee Chef/Puppet Vagrant

Page 80: Infrastructure as Code - ABUG Session

Kickstart/Preseed/Autoyast/

AutoUnattend

Git Repo Git Repo

Cookbooks/Manifests

Vagrantfile

Git Repo

Git Repo

Application Code

Shared “codebase”♥

Page 81: Infrastructure as Code - ABUG Session

Kickstart/Preseed/Autoyast/

AutoUnattend

Git Repo

Git Repo

Cookbooks/Manifests

Vagrantfile

Git Repo

Git Repo

Application Code

Co-Ownership♥

DEV & OPSpairing

Page 82: Infrastructure as Code - ABUG Session

More Ops into Dev

• can we speed up this provisioning?

• we need a migration script from vX -> vY

• we need start/stop scripts

• we need consistent data restore

Page 83: Infrastructure as Code - ABUG Session

Synchronized Release Cycle

Application vX

System vX

Application vX+1

System vX+1

Page 84: Infrastructure as Code - ABUG Session

Tools/Config Consistency

Cookbooks/Manifests

Cookbooks/Manifests

DEV PROD

Provisionerchef/puppet/script

Provisionerchef/puppet/script

Kickstart/Preseed/Autoyast/

AutoUnattend

Kickstart/Preseed/Autoyast/

AutoUnattend

Page 85: Infrastructure as Code - ABUG Session

Disposable Test Environments♥

Cookbooks/Manifests

Cookbooks/Manifests

DEV PROD

Provisionerchef/puppet/script

Provisionerchef/puppet/script

Kickstart/Preseed/Autoyast/

AutoUnattend

Kickstart/Preseed/Autoyast/

AutoUnattend

TEST/QA

http://paperairoplane.net/?p=240

Cookbooks/Manifests

Provisionerchef/puppet/script

Kickstart/Preseed/Autoyast/

AutoUnattend

Page 86: Infrastructure as Code - ABUG Session

Reuse Workflow

Vagrant

https://github.com/geemus/fog

Page 88: Infrastructure as Code - ABUG Session

http://marketplace.eclipse.org/node/519961#.UKISB-Oe-d4

VAGRANT ECLIPSE INTEGRATION

Page 90: Infrastructure as Code - ABUG Session

VAGRANT - CLOJURE

https://github.com/tbatchelli/vmfest

Page 91: Infrastructure as Code - ABUG Session

VAGRANT - JAVA

https://github.com/guigarage/vagrant-binding

Page 92: Infrastructure as Code - ABUG Session

UNIT TESTING

Page 96: Infrastructure as Code - ABUG Session

DON’T TEST YOUR CONFIG MANAGEMENT

TEST YOUR LOGIC

NOT

Was the package installed

YES

If (OS=’X’ ) and (file exists) ...

did it give an error?

Page 97: Infrastructure as Code - ABUG Session

FAKE THE FACTS

Page 99: Infrastructure as Code - ABUG Session

AUTO-TRIGGER TESTS RUN

https://github.com/guard/guard-chefhttps://github.com/alister/guard-puppet-linthttps://github.com/johnbintz/guard-puppet

https://github.com/guard/guard-rspec

CODE EDIT

AUTO RUNFEEDBACK

Page 100: Infrastructure as Code - ABUG Session

CI INTEGRATION

Page 101: Infrastructure as Code - ABUG Session

https://github.com/nicksieger/ci_reporter

Junit processor for Ruby

Page 102: Infrastructure as Code - ABUG Session

SYNTAX CHECKSCOMPILE CHECKS

UNIT TESTS

SMOKE TESTS

NO VM NEEDED

REAL VM

Page 103: Infrastructure as Code - ABUG Session

SMOKE TESTING(ON REAL MACHINE)

Code Applied

CLEAN VM

STATE A STATE BCode Run Run TestsCreate VM

SNAPSHOT

Page 105: Infrastructure as Code - ABUG Session

RE-USABLE CUCUMBER STEPS

https://github.com/hedgehog/cukenhttps://github.com/cucumber/aruba

http://www.cucumber-chef.org/

Page 106: Infrastructure as Code - ABUG Session

https://github.com/calavera/minitest-chef-handlerhttps://github.com/jedi4ever/puppet-assert

Validate “inside” the provision-run cycle

Page 107: Infrastructure as Code - ABUG Session

VM CREATION IS EXPENSIVE

https://github.com/jedi4ever/saharahttps://github.com/t9md/vagrant-snap

Code Applied

CLEAN VM

STATE A STATE BCode Run Run TestsCreate VM

SNAPSHOT

ROLLBACK

Page 109: Infrastructure as Code - ABUG Session

USEFULVAGRANT PLUGINS

https://github.com/riotgames/vagrant-berkshelf

https://github.com/schisamo/vagrant-omnibus

Page 111: Infrastructure as Code - ABUG Session

https://travis-ci.org/

Uses vagrant & veewee

Page 112: Infrastructure as Code - ABUG Session

TARGETED TESTINGIMPACT OF CHANGE

https://github.com/jedi4ever/puppet-cichttps://github.com/jonlives/knife-preflight

ROLE1

ROLE2

ROLEN

MODULEA

MODULEB

MODULEC

MODULE...

Real VM testingis expensive

Only test what’s needed

Page 113: Infrastructure as Code - ABUG Session

PERFORMANCE/METRICS

Page 116: Infrastructure as Code - ABUG Session

“It works on my machine”

Page 117: Infrastructure as Code - ABUG Session

For Devs(Test Code)

Page 118: Infrastructure as Code - ABUG Session

For Ops(Test Manifests)

Page 119: Infrastructure as Code - ABUG Session

For QA(Explore)

Page 120: Infrastructure as Code - ABUG Session

For Sales(To show off)

Page 121: Infrastructure as Code - ABUG Session

Bridgingfour worlds

without changing!

http://www.jedi.be/blog/2011/03/28/using-vagrant-as-a-team/

Page 123: Infrastructure as Code - ABUG Session

QUESTIONS?

Page 124: Infrastructure as Code - ABUG Session
Page 125: Infrastructure as Code - ABUG Session
Page 126: Infrastructure as Code - ABUG Session

OLDER OR RELATED STUFF

Page 128: Infrastructure as Code - ABUG Session

LOCAL VM TESTING

http://www.cucumber-chef.org/

https://github.com/exceedhl/toft

Faster testing via LXC

spinning up a vm is expensiveunless in container

EC2+LXC

Vagrant+LXC

Page 132: Infrastructure as Code - ABUG Session

https://github.com/rtyler/blimpy

https://github.com/jedi4ever/mccloud/

Vagrant ‘clones’

EC2, KVM, FUSION,HOSTS, Vagrant

EC2

https://github.com/neerolyte/vagueanthttps://github.com/lstoll/tenderloin FUSION

LXC

Page 136: Infrastructure as Code - ABUG Session

http://saltstack.org/

Page 143: Infrastructure as Code - ABUG Session

VENDORING

Page 146: Infrastructure as Code - ABUG Session

http://rundeck.org/

Page 149: Infrastructure as Code - ABUG Session

https://github.com/rerun/rerun

Page 150: Infrastructure as Code - ABUG Session

AUTHENTICATION

Page 151: Infrastructure as Code - ABUG Session

DASHBOARDS

Page 155: Infrastructure as Code - ABUG Session

http://theforeman.org/