Upload
martin-alfke
View
760
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Puppet User Group Berlin Q1 meetup: Introduction to the new, experimental puppet parser http://www.meetup.com/Puppet-User-Group-Berlin/events/145643562/
Citation preview
© Martin Alfke - 2014
Puppet Experimental Features
An introduction to new, experimental features !
Martin Alfke <[email protected]>
© Martin Alfke - 2014
• Future Parser
• Manifest Ordering
• Hiera Data in Modules
Puppet Experimental Features
© Martin Alfke - 2014
Future Parser
• armature test branches
• experimental
• may change without further notice
© Martin Alfke - 2014
Future Parser
• Lambdas and Iteration
• Other Langauge Features
• Language Restrictions
• Error Reporting
© Martin Alfke - 2014
Future Parser
• future parser has to be enabled
# master [master] parser = future !# masterless [main] parser = future !#cli —parser future
© Martin Alfke - 2014
Future Parser
• Lambdas and Iteration
© 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” }
© 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] }
© 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 }
© 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” }
© 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” }
© Martin Alfke - 2014
Future Parser
• Lambdas and Iteration
• Other Langauge Features
© 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
© Martin Alfke - 2014
Future Parser
• Lambdas and Iteration
• Other Langauge Features
• Expression as statement
• Array/Hash literals
notice([‘1’,’2’][1]) result: 2 !
© 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]
© 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 }
© 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)}”
© Martin Alfke - 2014
Future Parser
• Lambdas and Iteration
• Other Langauge Features
• Language Restrictions
© 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
© Martin Alfke - 2014
Future Parser
• Lambdas and Iteration
• Other Langauge Features
• Language Restrictions
• no user defined numeric variables
• no capitalized variables
$FOO = 10 <- breaks
© 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
© Martin Alfke - 2014
Future Parser
• Lambdas and Iteration
• Other Langauge Features
• Language Restrictions
• Error Reporting
© 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 …
© 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
© Martin Alfke - 2014
Manifest Ordering
• MOAR (manifest order analysis of resources)
• requires 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]
© Martin Alfke - 2014
Hiera Data in Modules
• put hiera data directly into your modules
• requires 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
© Martin Alfke - 2014
Hiera Data in Modules<modulepath>/<modulename>/
data/
osfamily/
RedHat.yaml
environment/
production.yaml
common.yaml
manifests/
files/
hiera.yaml
© Martin Alfke - 2014
Hiera Data in Modules
• needs hiera.yaml in module
<modulepath></modulename>/hiera.yaml
—- version: 2
© 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
© Martin Alfke - 2014
Hiera Data in Modules
• explizit lookups work like hiera v1
class my class ( $myvar ){ } !hiera-data: class::myvar: ‘value’
© Martin Alfke - 2014
Hiera Data in Modules
• implizit lookups use the lookup function
class my class ( $myvar = lookup(‘myvar’) ){ } !hiera-data: myvar: ‘value’
© 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)}’
© 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
© Martin Alfke - 2014
Puppet Experimental Features
Thank you !
Questions?