Puppet future parser

1,827 views

Published on

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

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,827
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Puppet future parser

  1. 1. Puppet Experimental Features An introduction to new, experimental features ! Martin Alfke <martin.alfke@buero20.org> © Martin Alfke - 2014
  2. 2. Puppet Experimental Features • • • Future Parser Manifest Ordering Hiera Data in Modules © Martin Alfke - 2014
  3. 3. Future Parser • armature test branches • experimental • may change without further notice © Martin Alfke - 2014
  4. 4. Future Parser • • • • Lambdas and Iteration Other Langauge Features Language Restrictions Error Reporting © Martin Alfke - 2014
  5. 5. Future Parser • future parser has to be enabled # master [master] parser = future ! # masterless [main] parser = future ! #cli —parser future © Martin Alfke - 2014
  6. 6. Future Parser • Lambdas and Iteration © Martin Alfke - 2014
  7. 7. 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
  8. 8. 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
  9. 9. Future Parser • Lambdas and Iteration • • • each (loop over array elements) map (transform into an array) filter (filters elements) • $a = [ 1,2,3] ! notice select($a) |$value| { $value < 2 } select in V3.3 © Martin Alfke - 2014
  10. 10. Future Parser • Lambdas and Iteration • • • • each (loop over array elements) map (transform into an array) $a = [ 1,2,3] ! filter (filters elements) reduce (reduce an array or hash) notice reduce($a) |$result,$value| { notice “$result + $value” } © Martin Alfke - 2014
  11. 11. Future Parser • Lambdas and Iteration • • • • • each (loop over array elements) map (transform into an array) $a = [ ‘fred’,20, ‘mary’,3] ! filter (filters elements) slice($a, 2) |$name, $value| { notice “$name = $value” } reduce (reduce an array) slice (slice an array or hash) © Martin Alfke - 2014
  12. 12. Future Parser • • Lambdas and Iteration Other Langauge Features © Martin Alfke - 2014
  13. 13. 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
  14. 14. Future Parser • • Lambdas and Iteration Other Langauge Features • • Expression as statement notice([‘1’,’2’][1]) result: 2 Array/Hash literals ! © Martin Alfke - 2014
  15. 15. Future Parser • • Lambdas and Iteration Other Langauge Features • • • Expression as statement [‘1’,’2’,’3’] + [‘4’,’5’,’6’] Array/Hash literals { a => 1 } + { b => 2 } Concatenation and append [1,2,3] << 10 [1,2,3] << [4,5,6] ! ! © Martin Alfke - 2014
  16. 16. Future Parser • • Lambdas and Iteration Other Langauge Features • • • • Expression as statement Array/Hash literals Concatenation and append unless $:memorysize > 1024 { $maxclient = 500 } else { $maxclient = 50 } unless with else © Martin Alfke - 2014
  17. 17. Future Parser • • Lambdas and Iteration Other Langauge Features • • • • • notice “This is a random number: ${fqdn_rand(30)}” Expression as statement Array/Hash literals Concatenation and append unless with else function class in interpolation © Martin Alfke - 2014
  18. 18. Future Parser • • • Lambdas and Iteration Other Langauge Features Language Restrictions © Martin Alfke - 2014
  19. 19. Future Parser • • • Lambdas and Iteration Other Langauge Features Language Restrictions • no user defined numeric variables $3 = ‘foo’ <- breaks ! ! define mytype ( $1, $2 ) { … } © Martin Alfke - 2014 <- breaks
  20. 20. Future Parser • • • Lambdas and Iteration Other Langauge Features Language Restrictions • • $FOO = 10 no user defined numeric variables no capitalized variables © Martin Alfke - 2014 <- breaks
  21. 21. Future Parser • • • Lambdas and Iteration Other Langauge Features Language Restrictions • • • no user defined numeric variables $a = 0x0EH <- hex ! $b = 0778 no capitalised variables number evaluation © Martin Alfke - 2014 <- oct
  22. 22. Future Parser • • • • Lambdas and Iteration Other Langauge Features Language Restrictions Error Reporting © Martin Alfke - 2014
  23. 23. Future Parser • • • • Lambdas and Iteration Other Langauge Features Language Restrictions $ puppet apply --parser future -e '$a = node "a+b" { }’ Error Reporting ! • ! 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 Position in line (in case of error) ! 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
  24. 24. Future Parser • • • • Lambdas and Iteration Other Langauge Features Language Restrictions ! max_errors Error Reporting • • puppet.conf: ! max_warnings Position in line (in case of error) ! max_deprecations error and warning feedback © Martin Alfke - 2014
  25. 25. Manifest Ordering • MOAR (manifest order analysis of resources) • requires future parser © Martin Alfke - 2014
  26. 26. Manifest Ordering • explizit dependency (default) • • + order from manifest • • manifest + random ordering • • title-hash [agent] ordering = [title-hash|manifest|random] random needs configuration in puppet.conf © Martin Alfke - 2014
  27. 27. Hiera Data in Modules • put hiera data directly into your modules • requires future parser © Martin Alfke - 2014
  28. 28. Hiera Data in Modules /etc/hiera/hiera.yaml • needs hiera V2 configuration version: 2 hierarchy: [ [ ‘osfamily’, ‘${osfamily}’, ’${osfamily}’ ], [ ‘environment’, ‘${environment}’, ‘$ {environment}’ ], [ ‘common’, ‘true’, ‘common’ ] ] backends: - yaml © Martin Alfke - 2014
  29. 29. Hiera Data in Modules <modulepath>/<modulename>/ data/ osfamily/ environment/ common.yaml manifests/ files/ hiera.yaml RedHat.yaml production.yaml © Martin Alfke - 2014
  30. 30. Hiera Data in Modules <modulepath></modulename>/ hiera.yaml • needs hiera.yaml in module —- version: 2 © Martin Alfke - 2014
  31. 31. Hiera Data in Modules common.yaml ntpserver: ntp1.ptb.de ! • osfamily/Debian.yaml hiera data follow common patterns ntpserver: 10.0.2.133 ! environment/dev.yaml ntpserver: 127.0.0.1 © Martin Alfke - 2014
  32. 32. Hiera Data in Modules • explizit lookups work like hiera v1 class my class ( $myvar ){ } ! hiera-data: class::myvar: ‘value’ © Martin Alfke - 2014
  33. 33. Hiera Data in Modules • implizit lookups use the lookup function class my class ( $myvar = lookup(‘myvar’) ){ } ! hiera-data: myvar: ‘value’ © Martin Alfke - 2014
  34. 34. 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
  35. 35. Puppet Experimental Features - Links • http://docs.puppetlabs.com/puppet/3/reference/ experiments_overview.html • https://puppetlabs.com/blog/introducing-manifestordered-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
  36. 36. Puppet Experimental Features Thank you ! Questions? © Martin Alfke - 2014

×