53
The Power of Puppet 4 Martin Alfke [email protected] Image: http://praetoris01.deviantart.com/

Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Embed Size (px)

Citation preview

Page 1: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

The Power of Puppet 4Martin Alfke [email protected]

Image: http://praetoris01.deviantart.com/

Page 2: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Martin Alfke

PL Training Partner

Module Contributor

!

ex-System Engineer

Infrastructure Architect

Page 3: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Welcome to Puppet 4April 15th 2015

https://puppetlabs.com/blog/say-hello-open-source-puppet-4

http://docs.puppetlabs.com/puppet/4.0/reference/index.html

Page 4: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Puppet Server & Packages

Page 5: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Puppet Server on JVM

Clojure

Trapperkeeper

JMX & internal metrics (PE only)

Page 6: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Puppet Packaging

AIO - like PE

New package name

New repository layout

No automatic update

Page 7: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Environments

Page 8: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Config environmentsStatic puppet.conf

[production] modulepath = /etc/puppet/production/modules manifests = /etc/puppet/production/manifests/site.pp ![test] modulepath = /etc/puppet/test/modules manifests = /etc/puppet/test/manifests/site.pp

Page 9: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Config environmentsDynamic puppet.conf

[master] modulepath = /etc/puppet/$environment/modules manifests = /etc/puppet/$environment/manifests/site.pp !

Page 10: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Directory environmentspuppet.conf

[master] environmentpath = /etc/puppet/environments !File system /etc/puppet/environments/ production/ modules/ manifests/ environment.conf test/ modules/ manifests/

Directory

Page 11: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Benefits

All environments in one place

Per environment configuration (environment.conf)

config_version = '/usr/bin/git --git-dir /etc/puppet/environments/$environment/.git rev-parse HEAD'

Newly added environments are available immediately

Page 12: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

r10k

Robot 10000

Manage environment in git branches

Puppetfile handles modules and versions

Page 13: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

New language features

Page 14: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Lambdas

Lambda

“a block of code that has parameters and can be invoked/called with arguments. A single lambda can be passed to a function”

$a = [1,2,3] each($a) |value| {notice $value }

Page 15: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Lambdas and functions

each - iterating over an array

map - transform an array or hash into a new array

filter - filters an array or hash

reduce - reduces an array or hash to a single value

slice - slices an array or hash into chunks

Page 16: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Using functions

Standard Puppet way:

function_name(argument) - each($variable)

Ruby way - chaining

argument.function_name - $variable.each

Page 17: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

EPP Template engine

Use Puppet $var instead of Ruby ERB @var

epp(filename)

inline_epp(epp_string)

Page 18: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

HEREDOC support

Like Shell HEREDOC

$multiline_text = @(EOF) # Managed by Puppet intended two spaces starting at beginning of line | intention starts at pipe sign EOF

Page 19: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

HEREDOC control character

- prevents a new line (like erb/epp)

@(“EOF”) - variable substition

@(EOF/tn) - enables char escapes

availabe char escapes: t,s,r,n,u,L,$

Default to off

Page 20: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Puppet 4.0 Data Bindings

New “hierarchy”:

global data (hiera)

data in environment (environment.conf)

data in modules

Page 21: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Puppet 4.0 Data in Envenvironment.conf

environment_data_provider = function

<env-root>/lib/puppet/functions/environment/data.rb

Puppet::Function.create_function(:’environment::data’) do def data () { ‘<class>::key’ => ‘value’, } end end

$variable = environment::data(‘key’) or automatic data bindings

Page 22: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Puppet 4.0 Data in Modules<moduleroot>/lib/puppet/bindings/mymodule/default.rb

Puppet::Bindings.newbindings(‘mymodule::default’) do … end

<moduleroot>/lib/puppet/functions/mymodule/data.rb

Puppet::Functions.create_function(:’mymodule::data’) do def data() { ‘mymodule::<class>::key’ => ‘value’, } end end !$var = mymodule::data(‘key’) or automatic data bindings

Page 23: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Puppet 4.0 Data Overriding

<env-root>/lib/puppet/functions/environment/data.rb

Puppet::Functions.create_function(:’environment::data’) do def data() { ‘<module>::<class>::key’ => ‘value’, } end end !used with automatic data bindings

Page 24: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Types, Types, Types

Page 25: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Why do we need types?class ssh ( $server = true, ) { if $server { include ssh::server } }

Parameterized class with parameter default

Page 26: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Why do we need types?class ssh ( $server = true, ) { if $server { include ssh::server } } !!class { ‘ssh’: server => ‘false’, }

!!!!!!!!!Usage of parameterised class. But: string instead of boolean !

Page 27: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Why do we need types?class ssh ( $server = true, ) { if validate_bool($server) { include ssh::server } } !!class { ‘ssh’: server => ‘false’, }

Parameterized class with parameter default !!Now with data validation (from stdlib)

Page 28: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Why do we need types?users::hash: ‘tom’: gid: ‘123’ home: ‘/home/tom’ managehome: false ‘ben’: gid: ‘124’ home: /home/ben managehome: ‘true’ ‘tim’: gid: 0125 home: ‘home/tim’ managehome: ‘false’

But: how to deal with more complex data? !!!!!!Missing quotes String instead of bool !Missing quotes and leading 0 Missing trailing slash String instead of bool

Page 29: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

We need types!class ssh ( Boolean $server = true, ) { if $server { include ssh::server } }

!Types, Types, Types, Types

Page 30: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

We need types!class ssh ( Boolean $server = true, ) { if $server { include ssh::server } } !!class { ‘ssh’: server => ‘false’, } !Error 400 on SERVER: Expected parameter 'server' of 'Class[Ssh]' to have type Boolean, got String

!!!!!!!!!We now get proper error messages.

Page 31: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

We want types!class users ( Hash $hash ) { $userarray = keys($hash) users::user_data { $userarray: } } !define users::user_data ( String $gid = $users::hash[$title][gid], String $home = $users::hash[$title][home], Boolean $managehome = $users::hash[$title][managehome], ) { }

Page 32: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Available TypesInteger[from, to]

Float[from,to]

Enum[*strings]

Pattern[*patterns]

Regexp[regexp]

Boolean

Array

Hash

Page 33: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Deprecations

Page 34: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Node Inheritancenode ‘basenode’ { include base include security } !node ‘www.server.com’ inherits basenode { include webserver }

# Dummy node as default !!!!# Real node inherits from basenode

Page 35: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Roles & Profilesnode ‘www.server.com’ { include webserver } !!class basenode { include base include security } !class webserver { include basenode }

# No more node inheritance !!!!# Define a class instead

Page 36: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Empty string comparison

An empty string compares to true instead of false

Page 37: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Empty string comparison$message = ‘’ !if $message { notify { “Message: ${message}”: } }

Empty string set as default !Check for variable existing and having content

Page 38: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Empty string comparison$message = ‘’ !if $message and $message != ‘’ { notify { “Message: ${message}”: } }

Empty string set as default !Check for variable existing and not empty string

Page 39: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Variable naming

A variable may not start with

a capital letter

an underscore (well. yes. it may. but. it’s private.)

Page 40: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Reference namingReference deprecation

capital letter on title

empty space between Type reference and title!Class [Ssh] !Class [‘ssh’] !Class[‘ssh’]

!Deprecated capital title !Empty space !Working

Page 41: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Hyphens in names

No more hyphens in

module name

class name

define name

Page 42: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Hyphens in names!<modulepath>/syslog-ng/ !<modulepath>/syslog_ng !class syslog-ng { … } !class syslog_ng { … }

!Deprecated !New name required !Deprecated !New name required (obious -> module/class naming convention)

Page 43: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Ruby DSLPuppet Ticket #18876

Closed 02/04/2013

New Ruby DSL API was revamped: “the number and severity of issues that came up in exploratory testing led us to the conclusion that it was not supportable code” - Puppet Dev ML - 01/26/2013

hostclass ‘ssh’ do end

Page 44: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

More deprecation

Relative resolution of class names - the reason why you want to use double colon - include ::ssh

Importing manifests

Matching numbers with regexp

Search function

Mutating arrays and hashes

Page 45: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

The 4 Powers of Puppet 4

Page 46: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Performance

Request response times and catalog compile times

!

!

Page 47: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Scalability

Switch on/off functionality for multi master setup

!

!

!

Page 48: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Measurability

Page 49: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Flexibility

Dealing with complex data natively in Puppet DSL

Page 50: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Upgrading to Puppet 4Breaks old style Puppet DSL code

Read documentation carefully

Run tests

Proposed way: new master

Page 51: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Text

Support all modulesWrite PR, file bug reports, fix issues

Page 52: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

More informationhttps://docs.puppetlabs.com/puppet/3.7/reference/deprecated_language.html

http://puppet-on-the-edge.blogspot.de/

http://docs.puppetlabs.com/puppet/4.0/reference/index.html

https://puppetlabs.com/blog/welcome-puppet-collections

Page 53: Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)

Text

The Power of Puppet 4Martin Alfke [email protected]

Image: http://praetoris01.deviantart.com/