Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Migrating to Puppet 4.0
0.27
2.7.x
3.x
3.x future parser
4.x
Puppet 4.0 Language
henrik.lindberg@puppetlabs.com
@hel
notice 1 => 1
notice 1 + 2 => syntax error
notice(1 + 2) => 3
notice 1,2,3 => 1 2 3
notice [1,2,3] => 1 2 3
notice [1,2],3...
Godzilla on Type
Juggling….
Puppet 4.0
• Language Cleanup
– Sanity, Principle of Least Surprise
– Expressions, Expressions, Expressions
• Features
– M...
Cleanup
• Language Specification – yes we have one
– https://github.com/puppetlabs/puppet-specifications
• Numbers are Num...
Migrating
Signs Your Goldfish is Dead
– Goldfish skin easily cracks
when flexed
– Goldfish is completely
dried out
– Eyes of goldfis...
4.0
+ future
3.8
2.7
To 4.x from < 3.8 no parser=future
• First Migrate to latest 3.8.x
– Coming from < 3.0 (released 2012)
• Dynamic Scoping r...
To 4.x from 3.8 with parser=future
• Relatively painless
– Standup a new 4.x master
• Packaging and paths changed in 4.x
–...
Migrating to Puppet 4.0
Language Changes
concat/append/merge/delete 1(6)
• Concatenate Arrays with +
[1,2,3] + [4,5,6] => [1,2,3,4,5,6]
• Merge Hashes with +
{a=>1...
unfold/splat 2(6)
• Unfold with unary *
$a = [2,3]
$b = [1, *$a, 4] => [1,2,3,4]
• Unfold in case option, selector and cal...
substrings 3(6)
• Substring in string
'cd' in "abcde" => true
• Substring with []
"xyzabcdef"[3,3] => "abc"
"xyzabcdef"[3]...
regexp string/interpolate 4(6)
• Matches with Regexp in String form
$a = "example.com"
$url =~ "http://$a.*"
Error message improvements 5(6)
• Detailed Error Messages
– Semantic validation unless lex or syntax errors
– Outputs posi...
Expression Based Grammar 6(6)
• if, unless, case are expressions
notice if 1 > 2 { true } else { false }
# => false
$a =
c...
Resource Expression
Local Defaults
file {
default:
mode => '444',
owner => 'admin';
title:
. . . ;
}
Unfold Hash of attributes
file {
default:
* => $defaults_hash;
'tmp/foo':
mode => '666',
* => $params_hash;
}
Create Resources Equiv. in Puppet
Resource[$type] {
default:
* => $defaults_hash;
$titles:
* => $params_hash;
}
LOOOOOOOPS
• Iterate over:
– Arrays
– Hashes
– Strings
– Integer ranges
• Implemented as functions taking callable code
bl...
each
• Do something with each element
• Returns LHS
[1,2,3].each |$x| { notice $x }
each([1,2,3]) |$x| { notice $x }
map
• Transform each element
• Returns transformed result
[1,2,3].map |$x| { $x*10 }
=> [10,20,30]
filter
• Produces elements that match
• Returns filtered result
[1,2,3].filter|$x| { $x >= 2 }
=> [2,3]
reduce
• Transforms / reduces many to one
• Feeds seed/previous result into next iteration
• Returns transformed result
[1...
What do you see?
Shout out the answer….
Next one….
Are you ready?
Two more…
ok?
The Puppet Type System
Cow
Integer
Puppet Types
• Puppet Types are first order objects (they can
be assigned and passed around in variables)
• Uses syntax fa...
Example Integer
# All integers
Integer
# All integers >=42
Integer[42]
# All integers >=42 and <=142
Integer[42,142]
Automatic type checking!
define mytype(Integer[80,443] $port){
# port guaranteed to be integer
# and between 80 and 443
# ...
Manual type checking!
define mytype($port) {
assert_type(Integer[80,443], $port) |$expected, $got| {
warn("Bad port $got, ...
Operations on Type
• Since a Type is a kind of Pattern…
– Match with =~ and !~
– Match in case expression
• Since Types ar...
Type Hierarchy
Any
|- Scalar
| |- Numeric
| | |- Integer[from, to]
| | |- Float[from, to]
| |
| |- String[from, to]
| | |-...
Type Hierarchy
Any
|- Collection
| |- Array[T]
| | |- Tuple[T*, from, to]
| |
| |- Hash[K, V]
| | |- Struct[{ key => T, .....
Type Hierarchy
Any
|- CatalogEntry
| |- Resource[type_name, title]
| |- Class[class_name]
|
|- Undef
|- Data
| |- Scalar
|...
EPP
EPP – Templates in Puppet
• Same template markup as ERB
– Logic is Puppet instead of Ruby
AND
• Can be parameterized !
• U...
Example EPP
$x = 'human'
inline_epp('This is not the <%= $x %> you are looking
for.', { 'x' => 'droid'})
# => 'This is not...
Heredoc
Puppet Heredoc
• For more detailed control over a block of text
• No, or selected set of escapes
• Interpolation or no int...
Heredoc - Syntax
@( ["]<endtag>["] [:<syntax>] [/<escapes>] )
<text>
[|][-] <endtag>
ENDS-HERE
anything not in <text>
"END...
Puppet Heredoc Example
#.........1.........2.........3.........4.........5....
$a = @(END)
This is indented 2 spaces in th...
Ruby API
Ruby API
• 4x Function API
– type checked
– dispatch to impl based on given types
– more powerful
– safer
• Binder
– compo...
Summary
• Language Cleanup
• More strict
• New Features
• Better Error Messages
• Iteration
• Type System
• Puppet Templat...
Enjoy Puppet 4
Links
• github/puppetlabs/puppet-specifications
• http://puppet-on-the-edge.blogspot.com/
• Twitter @hel
• IRC helindbe
Just use PE the next time, ok?
Migrating to Puppet 4.0
Migrating to Puppet 4.0
Migrating to Puppet 4.0
Migrating to Puppet 4.0
Migrating to Puppet 4.0
Migrating to Puppet 4.0
Migrating to Puppet 4.0
Prochain SlideShare
Chargement dans…5
×

Migrating to Puppet 4.0

1 241 vues

Publié le

Puppet Camp Stockholm Slide Deck

Publié dans : Technologie
  • Soyez le premier à commenter

Migrating to Puppet 4.0

  1. 1. Migrating to Puppet 4.0
  2. 2. 0.27
  3. 3. 2.7.x
  4. 4. 3.x
  5. 5. 3.x future parser
  6. 6. 4.x
  7. 7. Puppet 4.0 Language henrik.lindberg@puppetlabs.com @hel
  8. 8. notice 1 => 1 notice 1 + 2 => syntax error notice(1 + 2) => 3 notice 1,2,3 => 1 2 3 notice [1,2,3] => 1 2 3 notice [1,2],3 => 1 2 3 notice 5 in [5] => true notice (4+1) in [5] => error, not a string notice 5 in [4+1] => false notice 5.0 in [5] => false notice(0xff =~ /5/) => false notice((0xfe+1) =~/5/) => true notice { a=>10 } => error, no title
  9. 9. Godzilla on Type Juggling….
  10. 10. Puppet 4.0 • Language Cleanup – Sanity, Principle of Least Surprise – Expressions, Expressions, Expressions • Features – Misc enhancements – Resource Expression Features – Iteration – Type System / Optional Typing – Embedded Puppet Templates (EPP) – Heredoc – Data in Modules and Environments
  11. 11. Cleanup • Language Specification – yes we have one – https://github.com/puppetlabs/puppet-specifications • Numbers are Numbers • No magic to-string for =~ !~ in • Upper case bare words are Type References • Empty string is not undef (and thus "thruty") • Interpolation follows specified rules • +=, []= removed, no more mutation
  12. 12. Migrating
  13. 13. Signs Your Goldfish is Dead – Goldfish skin easily cracks when flexed – Goldfish is completely dried out – Eyes of goldfish are concave instead of convex – Pupils of goldfish are gray – Body parts of the goldfish are clearly missing
  14. 14. 4.0 + future 3.8 2.7
  15. 15. To 4.x from < 3.8 no parser=future • First Migrate to latest 3.8.x – Coming from < 3.0 (released 2012) • Dynamic Scoping removed • Address Deprecations – Switch to Directory Environments • Legacy Environments removed in 4.x – Use PE Catalog Preview with same code in two environments • (demos on youtube) • Turn on future parser in one to help with migration to 4.x Language • FOSS users can use similar free catalog compare tools (with more manual work) – Do changes in backwards compatible way – Update modules – Gradually migrate nodes – "future parser" production safe
  16. 16. To 4.x from 3.8 with parser=future • Relatively painless – Standup a new 4.x master • Packaging and paths changed in 4.x – The "all in one" agent – Same Ruby everywhere – New location for config files, hiera data etc. • Enjoy new PE 2015.3 / 4.3 features – Application Management – Data in Modules
  17. 17. Migrating to Puppet 4.0
  18. 18. Language Changes
  19. 19. concat/append/merge/delete 1(6) • Concatenate Arrays with + [1,2,3] + [4,5,6] => [1,2,3,4,5,6] • Merge Hashes with + {a=>1} + {b=>2} => {a=>1, b=>2} • Delete with - [1,2,3] – [2, 3] => [1] {a=>1, b=>2, c=>3} – [a,c] => {b=>2} • Append to Array with << [1,2,3] << 4 => [1,2,3,4] [1,2,3] << [4,5,6] => [1,2,3,[4,5,6]]
  20. 20. unfold/splat 2(6) • Unfold with unary * $a = [2,3] $b = [1, *$a, 4] => [1,2,3,4] • Unfold in case option, selector and call $a = [1,2,3] case 1 { *$a : { # 1 or 2 or 3 } } notice *$a => 1,2,3 notice $a => [1,2,3]
  21. 21. substrings 3(6) • Substring in string 'cd' in "abcde" => true • Substring with [] "xyzabcdef"[3,3] => "abc" "xyzabcdef"[3] => "a" "xyzabcdef"[3,-2] => "abcde"
  22. 22. regexp string/interpolate 4(6) • Matches with Regexp in String form $a = "example.com" $url =~ "http://$a.*"
  23. 23. Error message improvements 5(6) • Detailed Error Messages – Semantic validation unless lex or syntax errors – Outputs position on line – Can report more than one error
  24. 24. Expression Based Grammar 6(6) • if, unless, case are expressions notice if 1 > 2 { true } else { false } # => false $a = case 2 { 1, 2, 3: { yes } default: { no } } # => $a == yes
  25. 25. Resource Expression
  26. 26. Local Defaults file { default: mode => '444', owner => 'admin'; title: . . . ; }
  27. 27. Unfold Hash of attributes file { default: * => $defaults_hash; 'tmp/foo': mode => '666', * => $params_hash; }
  28. 28. Create Resources Equiv. in Puppet Resource[$type] { default: * => $defaults_hash; $titles: * => $params_hash; }
  29. 29. LOOOOOOOPS • Iterate over: – Arrays – Hashes – Strings – Integer ranges • Implemented as functions taking callable code blocks (lambdas) = open design • Calls can now be expressed from left to right using '.' notation
  30. 30. each • Do something with each element • Returns LHS [1,2,3].each |$x| { notice $x } each([1,2,3]) |$x| { notice $x }
  31. 31. map • Transform each element • Returns transformed result [1,2,3].map |$x| { $x*10 } => [10,20,30]
  32. 32. filter • Produces elements that match • Returns filtered result [1,2,3].filter|$x| { $x >= 2 } => [2,3]
  33. 33. reduce • Transforms / reduces many to one • Feeds seed/previous result into next iteration • Returns transformed result [1,2,3].reduce |$result, $x| { $result + $x } => 6
  34. 34. What do you see? Shout out the answer….
  35. 35. Next one…. Are you ready?
  36. 36. Two more… ok?
  37. 37. The Puppet Type System Cow Integer
  38. 38. Puppet Types • Puppet Types are first order objects (they can be assigned and passed around in variables) • Uses syntax familiar from Resource – i.e. Class, File, User, where [ ] applied to the type makes it more specific – e.g. File['foo']
  39. 39. Example Integer # All integers Integer # All integers >=42 Integer[42] # All integers >=42 and <=142 Integer[42,142]
  40. 40. Automatic type checking! define mytype(Integer[80,443] $port){ # port guaranteed to be integer # and between 80 and 443 # otherwise an error }
  41. 41. Manual type checking! define mytype($port) { assert_type(Integer[80,443], $port) |$expected, $got| { warn("Bad port $got, expected $expected. Using port 80.") 80 } } • Code block called if given does not match • …do what you want, fail, warn, return default
  42. 42. Operations on Type • Since a Type is a kind of Pattern… – Match with =~ and !~ – Match in case expression • Since Types are defined in a hierarchy: – Compare types with <, <=, >, >= # is $x an integer ? $x =~ Integer # is $t more specific than Integer $t = Integer[80, 144] $t < Integer
  43. 43. Type Hierarchy Any |- Scalar | |- Numeric | | |- Integer[from, to] | | |- Float[from, to] | | | |- String[from, to] | | |- Enum[*strings] | | |- Pattern[*patterns] | | | |- Boolean | |- Regexp[pattern_string]
  44. 44. Type Hierarchy Any |- Collection | |- Array[T] | | |- Tuple[T*, from, to] | | | |- Hash[K, V] | | |- Struct[{ key => T, ...}] | |- Variant[T*] |- Optional[T] | |- Undef |- Default | |- Type[T]
  45. 45. Type Hierarchy Any |- CatalogEntry | |- Resource[type_name, title] | |- Class[class_name] | |- Undef |- Data | |- Scalar | |- Array[Data] | |- Hash[Scalar, Data] | |- Undef
  46. 46. EPP
  47. 47. EPP – Templates in Puppet • Same template markup as ERB – Logic is Puppet instead of Ruby AND • Can be parameterized ! • Use functions epp(template) inline_epp(string) • instead of template() inline_template()
  48. 48. Example EPP $x = 'human' inline_epp('This is not the <%= $x %> you are looking for.', { 'x' => 'droid'}) # => 'This is not the droid you are looking for.' <%- |$x = 'human'| -%> This is not the <%= $x %> you are looking for. $x = 'human' inline_epp('This is not the <%= $x %> you are looking for.') # => 'This is not the human you are looking for.'
  49. 49. Heredoc
  50. 50. Puppet Heredoc • For more detailed control over a block of text • No, or selected set of escapes • Interpolation or no interpolation • Can be syntax checked by parser (JSon in core, can add plugin language support) • Control over left margin
  51. 51. Heredoc - Syntax @( ["]<endtag>["] [:<syntax>] [/<escapes>] ) <text> [|][-] <endtag> ENDS-HERE anything not in <text> "ENDS-HERE" with interpolation :json syntax check result /tsrn$L turns on escape / turns on all | set left margin - trim trailing t tab s space r return n new-line $ $ L <end of line>
  52. 52. Puppet Heredoc Example #.........1.........2.........3.........4.........5.... $a = @(END) This is indented 2 spaces in the source, but produces a result flush left with the initial 'T' This line is thus indented 2 spaces. | END #.........1.........2.........3.........4.........5.... foo(@(FIRST), @(SECOND)) This is the text for the first heredoc FIRST This is the text for the second SECOND
  53. 53. Ruby API
  54. 54. Ruby API • 4x Function API – type checked – dispatch to impl based on given types – more powerful – safer • Binder – composable type safe injection – for plugins and data (e.g. syntax checkers, data providers)
  55. 55. Summary • Language Cleanup • More strict • New Features • Better Error Messages • Iteration • Type System • Puppet Templates – EPP • Heredoc
  56. 56. Enjoy Puppet 4
  57. 57. Links • github/puppetlabs/puppet-specifications • http://puppet-on-the-edge.blogspot.com/ • Twitter @hel • IRC helindbe
  58. 58. Just use PE the next time, ok?

×