puppet future parser

36
© Martin Alfke - 2014 Puppet Experimental Features An introduction to new, experimental features Martin Alfke <[email protected]>

Upload: martin-alfke

Post on 10-May-2015

759 views

Category:

Technology


0 download

DESCRIPTION

Puppet User Group Berlin Q1 meetup: Introduction to the new, experimental puppet parser http://www.meetup.com/Puppet-User-Group-Berlin/events/145643562/

TRANSCRIPT

Page 1: Puppet future parser

© Martin Alfke - 2014

Puppet Experimental Features

An introduction to new, experimental features !

Martin Alfke <[email protected]>

Page 2: Puppet future parser

© Martin Alfke - 2014

• Future Parser

• Manifest Ordering

• Hiera Data in Modules

Puppet Experimental Features

Page 3: Puppet future parser

© Martin Alfke - 2014

Future Parser

• armature test branches

• experimental

• may change without further notice

Page 4: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Language Restrictions

• Error Reporting

Page 5: Puppet future parser

© Martin Alfke - 2014

Future Parser

• future parser has to be enabled

# master [master] parser = future !# masterless [main] parser = future !#cli —parser future

Page 6: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

Page 7: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• each (loop over arrays and hashes)

$a = [ 1,2,3] !each($a) | $value | { notice $value } !!$h = { ‘1’ => [‘a’,’b’,’c’], ‘2’ => ‘foo’ } each($h) | $key, $value | { notice “$key = $value” }

Page 8: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• each (loop over array elements)

• map (transform into an array)

• collect in V3.3

$a = [ 1,2,3] !$a.collect | $value | { notice $value } !!$h = { ‘1’ => [‘a’,’b’,’c’], ‘2’ => ‘foo’ } !$c.collect | $value | { notice $value[0] } $c.collect | $value | { notice $value[1] }

Page 9: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• each (loop over array elements)

• map (transform into an array)

• filter (filters elements)

• select in V3.3

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

Page 10: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• each (loop over array elements)

• map (transform into an array)

• filter (filters elements)

• reduce (reduce an array or hash)

$a = [ 1,2,3] !notice reduce($a) |$result,$value| { notice “$result + $value” }

Page 11: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• each (loop over array elements)

• map (transform into an array)

• filter (filters elements)

• reduce (reduce an array)

• slice (slice an array or hash)

$a = [ ‘fred’,20, ‘mary’,3] !slice($a, 2) |$name, $value| { notice “$name = $value” }

Page 12: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

Page 13: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Expression as statement $a = [ 1,2,3] $b = [‘a’,’b’,’c’] !notice $a + $b !or !notice $a << $b

Page 14: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Expression as statement

• Array/Hash literals

notice([‘1’,’2’][1]) result: 2 !

Page 15: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Expression as statement

• Array/Hash literals

• Concatenation and append

[‘1’,’2’,’3’] + [‘4’,’5’,’6’] !{ a => 1 } + { b => 2 } ![1,2,3] << 10 [1,2,3] << [4,5,6]

Page 16: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Expression as statement

• Array/Hash literals

• Concatenation and append

• unless with else

unless $:memorysize > 1024 { $maxclient = 500 } else { $maxclient = 50 }

Page 17: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Expression as statement

• Array/Hash literals

• Concatenation and append

• unless with else

• function class in interpolation

notice “This is a random number: ${fqdn_rand(30)}”

Page 18: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Language Restrictions

Page 19: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Language Restrictions

• no user defined numeric variables

$3 = ‘foo’ <- breaks !!define mytype ( $1, $2 ) { … } <- breaks

Page 20: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Language Restrictions

• no user defined numeric variables

• no capitalized variables

$FOO = 10 <- breaks

Page 21: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Language Restrictions

• no user defined numeric variables

• no capitalised variables

• number evaluation

$a = 0x0EH <- hex !$b = 0778 <- oct

Page 22: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Language Restrictions

• Error Reporting

Page 23: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Language Restrictions

• Error Reporting

• Position in line (in case of error)

$ puppet apply --parser future -e '$a = node "a+b" { }’ !Error: Invalid use of expression. A Node Definition does not produce a value at line 1:6 !Error: The hostname 'a+b' contains illegal characters (only letters, digits, '_', '-', and '.' are allowed) at line 1:11 !Error: Classes, definitions, and nodes may only appear at toplevel or inside other classes at line 1:6 !Error: Could not parse for environment production: Found 3 errors. Giving up on node …

Page 24: Puppet future parser

© Martin Alfke - 2014

Future Parser

• Lambdas and Iteration

• Other Langauge Features

• Language Restrictions

• Error Reporting

• Position in line (in case of error)

• error and warning feedback

puppet.conf: !max_errors !max_warnings !max_deprecations

Page 25: Puppet future parser

© Martin Alfke - 2014

Manifest Ordering

• MOAR (manifest order analysis of resources)

• requires future parser

Page 26: Puppet future parser

© Martin Alfke - 2014

Manifest Ordering

• explizit dependency (default)

• title-hash

• + order from manifest

• manifest

• + random ordering

• random

• needs configuration in puppet.conf

[agent]

ordering = [title-hash|manifest|random]

Page 27: Puppet future parser

© Martin Alfke - 2014

Hiera Data in Modules

• put hiera data directly into your modules

• requires future parser

Page 28: Puppet future parser

© Martin Alfke - 2014

Hiera Data in Modules

• needs hiera V2 configuration

/etc/hiera/hiera.yaml

version: 2 hierarchy: [ [ ‘osfamily’, ‘${osfamily}’, ’${osfamily}’ ], [ ‘environment’, ‘${environment}’, ‘${environment}’ ], [ ‘common’, ‘true’, ‘common’ ] ] backends: - yaml

Page 29: Puppet future parser

© Martin Alfke - 2014

Hiera Data in Modules<modulepath>/<modulename>/

data/

osfamily/

RedHat.yaml

environment/

production.yaml

common.yaml

manifests/

files/

hiera.yaml

Page 30: Puppet future parser

© Martin Alfke - 2014

Hiera Data in Modules

• needs hiera.yaml in module

<modulepath></modulename>/hiera.yaml

—- version: 2

Page 31: Puppet future parser

© Martin Alfke - 2014

Hiera Data in Modules

• hiera data follow common patterns

common.yaml

ntpserver: ntp1.ptb.de !

osfamily/Debian.yaml

ntpserver: 10.0.2.133 !

environment/dev.yaml

ntpserver: 127.0.0.1

Page 32: Puppet future parser

© Martin Alfke - 2014

Hiera Data in Modules

• explizit lookups work like hiera v1

class my class ( $myvar ){ } !hiera-data: class::myvar: ‘value’

Page 33: Puppet future parser

© Martin Alfke - 2014

Hiera Data in Modules

• implizit lookups use the lookup function

class my class ( $myvar = lookup(‘myvar’) ){ } !hiera-data: myvar: ‘value’

Page 34: Puppet future parser

© Martin Alfke - 2014

Hiera Data in Modules

• hiera data now use puppet variable syntax

myvar: ‘Hi ${othervar}’ !myvar2: ‘Hello ${array[2]}’ !myvar3: ‘Hello ${lookup(akey)}’

Page 35: Puppet future parser

© Martin Alfke - 2014

Puppet Experimental Features - Links

• http://docs.puppetlabs.com/puppet/3/reference/experiments_overview.html

• https://puppetlabs.com/blog/introducing-manifest-ordered-resources

• https://github.com/puppetlabs/armatures/blob/master/arm-9.data_in_modules/index.md

• https://github.com/pro-puppet/puppet-module-startrek

• https://github.com/puppetlabs/armatures

Page 36: Puppet future parser

© Martin Alfke - 2014

Puppet Experimental Features

Thank you !

Questions?