Transcript
Page 1: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Manageable Puppetinfrastructure

~April 2014 edition~

PuppetCamp Berlin

Ger Apeldoorn - http://puppetspecialist.nl

1 / 44

Page 2: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Freelance Puppet Consultant

Trainer for PuppetLabs Benelux

Who's this?

2 / 44

Page 3: Puppet Camp Berlin 2014: Manageable puppet infrastructure

ScopeAlso... why this talk?

3 / 44

Page 4: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Commonpitfalls

4 / 44

Page 5: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Pitfalls

Cause & effectPitfalls

Lots of WorkaroundsUnmaintainable codebaseCollaboration difficulties

5 / 44

Page 6: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Pitfalls

Cause & effect

Quick Wins

Fix your codebase!Quick wins:

Move data to Hiera

Implement Code Review

Use Puppet-lint in a git-hook

REFACTOR CONSTANTLY

6 / 44

Page 7: Puppet Camp Berlin 2014: Manageable puppet infrastructure

A Manageable DesignApril 2014 edition

7 / 44

Page 8: Puppet Camp Berlin 2014: Manageable puppet infrastructure

RequirementsWhadda we need

8 / 44

Page 9: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Our environment should be:Easy to Use

Easy to Comprehend

Easy to Update

and... Safe

9 / 44

Page 10: Puppet Camp Berlin 2014: Manageable puppet infrastructure

This stuffisn't exactly

easy

10 / 44

Page 11: Puppet Camp Berlin 2014: Manageable puppet infrastructure

But we cán make it safe andmanageable

11 / 44

Page 12: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Requirements

Easy to:UseComprehendUpdate

Safe

SafeUse environments to test everything

Create a huge testing environment

Use Git to promote your code

12 / 44

Page 13: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Requirements

Easy to:UseComprehendUpdate

Safe

Manageable

ManageableKeep a consistent module structure

Using roles for abstraction

Facilitate collaboration

13 / 44

Page 14: Puppet Camp Berlin 2014: Manageable puppet infrastructure

DomainsServer Roles

All things data

Deployment & Workflow

14 / 44

Page 15: Puppet Camp Berlin 2014: Manageable puppet infrastructure

OverviewSoftware Components

15 / 44

Page 16: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Software ComponentsPuppet Enterprise or The Foreman

Hiera and hiera-eyaml (Hierarchical Data lookup)

Gerrit (Code review system)

Git (what else?)

Git Flow, adapted version for Gerrit

R10K (Environment deployment tool)16 / 44

Page 17: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Domain #1:

Server Roles

17 / 44

Page 18: Puppet Camp Berlin 2014: Manageable puppet infrastructure

A layer of abstraction

18 / 44

Page 19: Puppet Camp Berlin 2014: Manageable puppet infrastructure

How to do it?Create roles moduleroot@puppet# puppet module generate gerapeldoorn-role

Create a base-role to cover generic settings# modules/role/manifests/base.pp:class role::base { include users include ssh include motd ...

19 / 44

Page 20: Puppet Camp Berlin 2014: Manageable puppet infrastructure

How to do it? -Cont'd-Put all required resources in the classes# modules/role/manifests/app.pp:class role::app { include apache include tomcat apache::virtualhost { 'default': ...

Include role in node definition# site.pp:node 'app01.autiplan.com' { include role::base include role::app}

20 / 44

Page 21: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Domain #2:

All things Data

21 / 44

Page 22: Puppet Camp Berlin 2014: Manageable puppet infrastructure

HieraHierarchical data lookup tool

22 / 44

Page 23: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Configured Hierarchy:#/etc/puppet/hiera.yaml::hierarchy: - "%{::clientcert}" - "%{::environment}" - common

Node app01.autiplan.com:

environment: testing

Hieradata# hiera/app01.autiplan.com.yaml---examplekey: value for \ app01.autiplan.com

# hiera/testing.yaml---examplekey: value for nodes in \ testing environment

# hiera/common.yaml---examplekey: value for all nodes

It's all about Hierarchy

What will be in $test?$test = hiera('examplekey')

23 / 44

Page 24: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Types of HieradataRegular values# hiera/app01.autiplan.com.yaml---examplekey: value

24 / 44

Page 25: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Types of HieradataArrays# hiera/app01.autiplan.com.yaml---array: [ item1, item2, item3 ]

otherarray: - item1 - item2 - item3

Note: Never use tabs in Hiera files!

25 / 44

Page 26: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Types of HieradataHashes# hiera/app01.autiplan.com.yaml---hash: key1: value key2: value

26 / 44

Page 27: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Types of HieradataCombinations# hiera/app01.autiplan.com.yaml---hash: key1: value key2: value key3: - arrayvalue1 - arrayvalue2 key4: subhashkey1: value subhashkey2: value

27 / 44

Page 28: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Hiera-related functions...and what to use them for

28 / 44

Page 29: Puppet Camp Berlin 2014: Manageable puppet infrastructure

What does it do?Retrieves the first-found value in thehierarchy. (top-down)

What to use it for?Basic variable-lookup.Very easy to create exceptions!

How to use it?

$smarthost = hiera('smarthost')

Example Hieradata# hiera/mail.autiplan.com.yaml---smarthost: smtp.myprovider.nl

# hiera/testing.yaml---smarthost: testsmtp.autiplan.com

# hiera/common.yaml---smarthost: mail.autiplan.com

hiera('key' [, default_value])

29 / 44

Page 30: Puppet Camp Berlin 2014: Manageable puppet infrastructure

What does it do?Retrieves an array or hash valuein the hierarchy, concatinates allfound results

What to use it for?Combining data from allhierarchy levels.

How to use it?

$users = hiera_array('users')

Example Hieradata# hiera/app01.autiplan.com.yaml---users: [ 'user1', 'user2' ]

# hiera/testing.yaml---users: [ 'testuser' ]

# hiera/common.yaml---users: [ 'user3', 'user4' ]

hiera_array('key' [, default_value]) (and hiera_hash)

30 / 44

Page 31: Puppet Camp Berlin 2014: Manageable puppet infrastructure

What does it do?Includes all classes listed in thearray that is loaded from Hiera.Takes elements from ALLhierarchy levels.

What to use it for?Lightweight ENC.Put all classes / roles in Hiera.

How to use it?

node default { hiera_include('roles')}

Example Hieradata# hiera/web01.autiplan.com.yaml---roles: - role::web

# hiera/common.yaml---roles: - role::base

hiera_include('classes')

31 / 44

Page 32: Puppet Camp Berlin 2014: Manageable puppet infrastructure

What does it do?Generates resources from aHASH.

What to use it for?Generate any resource based ondata from Hiera.Can also be used withhiera_hash to create resourcesfrom all levels!

How to use it?

create_resources ('apache::vhost', hiera('vhosts', {}))

Example Hieradata# hiera/web01.autiplan.com.yaml---vhosts: autiplan.com: alias: www.autiplan.com autiplan.dk: alias: www.autiplan.dk docroot: /var/www/html/autiplan.dk autiplan.nl: alias: www.autiplan.nl cdn.autiplan.com: port: 81 docroot: /var/www/html/cdn

create_resources('type', HASH [, default_values])

32 / 44

Page 33: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Data bindingsAuto-loading of Hiera data for parameterized classes.

33 / 44

Page 34: Puppet Camp Berlin 2014: Manageable puppet infrastructure

What does it do?Automatically loads classparameters from Hiera.

What to use it for?Specify all class parameters inHiera.Use all hierarchical benefits forclass parameters.Simplify the use ofparameterized classes.

How to use it?

include mysql::server

Example Hieradata# hiera/web01.autiplan.com.yaml---mysql::server::root_password: m0ars3cr3t

# hiera/common.yaml---mysql::server::root_password: t0ps3cr3tmysql::server::package_name: mysql-servermysql::server::restart: true

Data bindings

34 / 44

Page 35: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Putting it all togetherAnything node-specific should be in Hiera!

35 / 44

Page 36: Puppet Camp Berlin 2014: Manageable puppet infrastructure

A Puppet Run: What calls what?

36 / 44

Page 37: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Domain #3:

Deployment & Workflow

37 / 44

Page 38: Puppet Camp Berlin 2014: Manageable puppet infrastructure

EnvironmentsKeeping the environmentalists happy

38 / 44

Page 39: Puppet Camp Berlin 2014: Manageable puppet infrastructure

EnvironmentsWhat is an environment?

Seperate modulepaths/site.pp.Common environments: development, testing, production.Nodes request a specific environment.

Why?Essential to prevent mistakes.NEVER edit code in production!The workflow helps us to 'promote' our code to production.

39 / 44

Page 40: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Demo!

40 / 44

Page 41: Puppet Camp Berlin 2014: Manageable puppet infrastructure

R10k overview

41 / 44

Page 42: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Final remarksKeep public modules as-is, wherever possible

Create wrapper classes in company-module.Create fork if needed, submit pull request for fixes.

Add forked module (gitrepo) to Puppetfile.

Think aheadAlways try to anticipate future applications.If it feels overly complicated, yer doin it wrong.Refactor!

42 / 44

Page 43: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Questions?

43 / 44

Page 44: Puppet Camp Berlin 2014: Manageable puppet infrastructure

Freelance Puppet Consultant

Trainer for PuppetLabs Benelux

Thank you!A howto of setting up this environment (and the workflow!) is available on my

blog: http://puppetspecialist.nl/mpi

44 / 44


Top Related