Puppet in the Enterprise

84
3XSSHWLQWKH(QWHUSU J^ecWiKf^_bb j^ecWi6dWhhWX_b_i$Yec

Transcript of Puppet in the Enterprise

Page 1: Puppet in the Enterprise

Puppet in the EnterpriseThomas Uphill

[email protected]

Page 2: Puppet in the Enterprise

Example Fileshttps://github.com/uphillian/lisa2014

Latest versionhttp://goo.gl/G0TLfJ

If you see something,say something!

Google Comments enabled

Page 3: Puppet in the Enterprise

Seriously, Trust Me...Animations Are Good things

Watch in Presentation Mode!

Page 5: Puppet in the Enterprise

Email server

Page 6: Puppet in the Enterprise

time shift configuration configuration

management"Tend the flock, not the sheep"

-- Me

Page 7: Puppet in the Enterprise

The Puppet Problem

Page 8: Puppet in the Enterprise

The Puppet Problem

system administrators❏ scripts❏ pipes/redirection❏ lazy

developers❏ objects❏ code reuse❏ lazy

Page 9: Puppet in the Enterprise

Puppet Problem

system administrators

developers

Page 10: Puppet in the Enterprise

node

package

package

package

package

package

package

user

user

user

user

group

group

group

serviceservice

service

service

service

file

file

file

Page 11: Puppet in the Enterprise

package

package

package

package

package

package

user

user

user

user

group

group

group

serviceservice

serviceservice

service

file

file

file

module

module

module

Page 12: Puppet in the Enterprise

classes modules nodes

Page 13: Puppet in the Enterprise

Roles and Profiles

modules

modules

profile

profile

noderole

Page 14: Puppet in the Enterprise

Roles and Profiles and Exceptions

modules

modules

profile

profile

noderole

ENC HieraCMDBLDAP

Page 15: Puppet in the Enterprise

Goal

node thx1138 { class { 'role::drupal7': }}

Page 16: Puppet in the Enterprise

The Puppet Problem

❏ Minimize exceptions❏ if else if else if else if else if else❏ case

❏ case❏ case

❏ case

Page 17: Puppet in the Enterprise

Hiera

Separating data from codeTechniques:

❏ Parameterized classes❏ hiera_include❏ fact based hierarchy

But first...custom facts

Page 18: Puppet in the Enterprise

Why?❏ facts are loaded and defined early in

catalog compilation❏ facts can be used in hiera hierarchy❏ facts can be used as selectors in case

statements

custom facts

Page 19: Puppet in the Enterprise

Two methods:❏ external facts

❏❏❏ (chmod +x)

❏ custom facts❏

custom facts

Page 20: Puppet in the Enterprise

External facts:❏ simpler to write❏ unavailable for first catalog

compile❏ cannot use facts

custom facts

http://bluehawk.monmouth.edu/~rclayton/web-pages/s11-503/recursion.jpg

Page 21: Puppet in the Enterprise

custom facts

written in rubycan access previously defined factspuppet 3+ ⇒ automatically sync'ed

Page 22: Puppet in the Enterprise

Parameterized Classes

❏ class accepts parameters(arguments)

Page 23: Puppet in the Enterprise

Parameterized Classes

When?❏ Include without modification:

❏ Include with modification❏

Page 24: Puppet in the Enterprise

parameterized class

Page 25: Puppet in the Enterprise

Automatic Parameter lookup

requires puppet 3+

Page 26: Puppet in the Enterprise

Hierarchy

where the node lives

geography/ip/timezone

/etc/hieradata/cunning/ pst.yaml cmt.yaml est.yaml

pst.yaml

Page 27: Puppet in the Enterprise

hiera_include

hiera_include('lookupkey','notfound')

❏ Lookup 'lookupkey' in hiera❏ include each class listed in 'lookupkey'

❏ if nothing found, include 'notfound'❏ call hiera_include from site.pp

site.pp

Page 28: Puppet in the Enterprise

fact based hierarchy

hiera.yaml

Page 29: Puppet in the Enterprise

fact based hierarchy

hiera.yaml

/hieradata

/is_virtual

true.yaml

false.yaml

common.yaml

site.pp…

true.yaml

virtual_machine/manifests/init.pp

notfound/manifests/init.pp

Page 30: Puppet in the Enterprise

fact based hierarchy - custom fact

hiera.yaml

/hieradata

/custom_fact

this.yaml

that.yaml

another.yaml

Page 31: Puppet in the Enterprise

Centralized or Not?

Page 32: Puppet in the Enterprise

Centralized/Decentralized

Page 33: Puppet in the Enterprise

Decentralized

puppet apply

role node

Page 34: Puppet in the Enterprise

Centralized

puppet agent

Scaling

Page 35: Puppet in the Enterprise

Scaling

What is the most important thing to remember about puppet?

Puppet is a web service.Puppet is a web service on port 8140Puppet is an SSL web service on port 8140

Page 36: Puppet in the Enterprise

Scaling

REST APIhttps://puppet:8140/environment/resource/key

Page 37: Puppet in the Enterprise

Scaling

Page 38: Puppet in the Enterprise

Scaling

❏❏❏

Page 39: Puppet in the Enterprise

Scaling/apache

Page 40: Puppet in the Enterprise

Scaling: does it actually work?

Demo 1:VM

- proxy- passenger- puppetdb / postgresql

Page 41: Puppet in the Enterprise

Infrastructure as CodeSoftware as a ServicePlatform as a Service

Page 42: Puppet in the Enterprise

developmentcontinuous integrationrefactoring

buzzword something

workflow

Page 43: Puppet in the Enterprise

Workflow

Decentralized:❏ create machine❏ install puppet❏ apply role❏ download code❏ puppet apply

Centralized:❏ create machine❏ install puppet❏ apply role❏ puppet agent

Page 44: Puppet in the Enterprise

Hardware

physical

virtual

Page 45: Puppet in the Enterprise

Virtual Hardware

virtual

local

cloud

Page 46: Puppet in the Enterprise

Bootstrapping

Decentralized:❏ create machine❏ install puppet

(bootstrap)❏ apply role❏ download code❏ puppet apply

Centralized:❏ create machine❏ install puppet

(bootstrap)❏ apply role❏ puppet agent

Page 47: Puppet in the Enterprise

Bootstrapping

Install Puppet❏

❏ install puppetlabs apt source❏

❏ install puppetlabs yum repo❏ tar file❏ port/brew install puppet

Page 48: Puppet in the Enterprise

Bootstrapping

Apply role❏ hiera

❏ ENCCMDB lookupLDAP lookup

❏ node definitionsite.pp

← doesn't scale well

Page 49: Puppet in the Enterprise

Bootstrapping

ensure puppet running❏ agent: service❏ apply: cron taskinstall puppet

Page 50: Puppet in the Enterprise

Workflow - creation

❏ Provision (VM/Physical)❏ Bootstrap puppet

❏ Assign role to node❏ Apply puppet (agent or apply)

❏ ensure puppet installed properly❏ ensure puppet running (service or cron task)

❏ Register node❏ monitoring / nagios

Page 51: Puppet in the Enterprise

Workflow - deletion

❏ Decommission (VM/Physical)❏ Remove role assignment

❏ hiera/enc/ldap❏ Delete from Reports

(foreman/console)❏ De-register node

❏ monitoring / nagios

Page 52: Puppet in the Enterprise

Workflow

Maximize return on investment:1. install puppet early2. apply bootstrap.pp manifest3. ***4. profit

Page 53: Puppet in the Enterprise

Scaling

Page 54: Puppet in the Enterprise

Workflow

OSTeam

ApplicationTeam

MiddlewareTeam

InfoSecTeam

Page 55: Puppet in the Enterprise

Workflow

OSTeam

ApplicationTeam

MiddlewareTeam

InfoSecTeam

automated workflow

Page 56: Puppet in the Enterprise

Workflow (code)

❏ Push code to masters❏ Branches

❏ Code promotion❏ Environments❏ Purge old

❏ Hieradata

Page 57: Puppet in the Enterprise

❏ defacto source code control for puppet

❏ integrates into workflow❏ cheap branches❏ hooks

Page 58: Puppet in the Enterprise

Git Hookshttp://goo.gl/dg5TVw

Page 59: Puppet in the Enterprise

❏ Branch is a reference❏ references are hashes❏ branches are cheap

Page 60: Puppet in the Enterprise

❏ branch == environment❏ directory environments (3.6+)

❏ directory with is the environment

Page 61: Puppet in the Enterprise

directory environments

branch

branch

Page 62: Puppet in the Enterprise

❏ repository 101❏ remote / origin❏ bare repos

gitserver

puppetworker

puppetworker

puppetworker

Page 63: Puppet in the Enterprise

❏ hooks❏ many hooks, two useful here:

separate who can do what❏

push code

Page 64: Puppet in the Enterprise

❏ puppet-synchttps://github.com/pdxcat/puppet-sync

❏ pull down a single git repo

puppet-sync

gitserver

puppetworker

puppetworker

puppetworker

Page 65: Puppet in the Enterprise

puppet-sync

Page 66: Puppet in the Enterprise

puppet-sync

Page 67: Puppet in the Enterprise

Up to here

● single git repository● clone to each master (worker/CA)● automated

Page 68: Puppet in the Enterprise

❏ multiple git repositories❏ librarian-puppet❏ r10k

Workflow

Page 69: Puppet in the Enterprise

Puppetfile

Page 70: Puppet in the Enterprise

r10k

https://github.com/adrienthebo/r10k❏ Uses Puppetfile❏ local cache❏ Configuration file: r10k.yaml

r10k.yaml

Page 71: Puppet in the Enterprise

r10kr10k.yaml

/var/lib/git/puppet.git

Puppetfile

dist, local, ours

Page 72: Puppet in the Enterprise

r10k

deploy using r10k

even better

Page 73: Puppet in the Enterprise

r10k post-receive (git hook)

Page 74: Puppet in the Enterprise

r10k Workflow

master repository

Puppetfile

ModulesModules

forge

git github

Page 75: Puppet in the Enterprise

r10k Workflow

master repository

"He who controls the spice controls the

universe"Baron Vladimir Harkonnen

Page 76: Puppet in the Enterprise

r10k Workflow

One repository per moduleModules included by Puppetfiler10k repo controls everything

Page 77: Puppet in the Enterprise

hiera

hieradata is in git alsogithook pushes hiera codehiera = exceptions add modules/profiles to a node

Page 78: Puppet in the Enterprise

hieradata - multiple teams

multiple backends OS Team ⇒ JSON App Team ⇒ YAML WebGui ⇒ Database

You can still use an ENC too.

Page 79: Puppet in the Enterprise

Goal

node thx1138 { class { 'role::drupal7': }}

Page 80: Puppet in the Enterprise

Real Goal

code

modulepath

automated

datahieradata

automated

code

data

"If you are editing code in /etc/puppet, you are doing it

wrong." - Me

Page 81: Puppet in the Enterprise

Bootable ISO

tutorial.htmlDemo 2, 3 and 4

Page 82: Puppet in the Enterprise

Troubleshooting

http://goo.gl/b2NISc

Page 83: Puppet in the Enterprise

Summary

Create a workflow/lifecycle for nodesCreate a workflow for code hieradataSeparate data from code: hieracreate a class hierarchy: roles/profilescentralize or decentralize: scaleKISS

Page 84: Puppet in the Enterprise

Questions?Comments?