O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Power of Puppet 4

8.111 visualizações

Publicada em

The Power of Puppet 4
New features
Deprecations and how to proceed

Publicada em: Tecnologia
  • Seja o primeiro a comentar

Power of Puppet 4

  1. 1. Text The Power of Puppet 4 Martin Alfke ma@example42.com
  2. 2. About me PL Training Partner Module Contributor Automation Enthusiast
  3. 3. Puppet Server & Packaging Environments New language features
  4. 4. Types, Types, Types Deprecations The 4 Powers of Puppet 4
  5. 5. Puppet Server & Packages
  6. 6. Puppet Server on JVM Closure Trapperkeeper JMX & internal metrics (PE only)
  7. 7. Puppet Packaging AIO - like PE New package name Discussion on mailinglist
  8. 8. Environments
  9. 9. Config environments Static 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
  10. 10. Config environments Dynamic puppet.conf [master] modulepath = /etc/puppet/$environment/modules manifests = /etc/puppet/$environment/manifests/site.pp !
  11. 11. Directory environments puppet.conf [master] environmentpath = /etc/puppet/environments ! File system /etc/puppet/environments/ production/ modules/ manifests/ environment.conf test/ modules/ manifests/ Directory
  12. 12. 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
  13. 13. r10k Robot 10000 Manage environment in git branches Puppetfile handles modules and versions
  14. 14. New language features
  15. 15. 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 }
  16. 16. 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
  17. 17. Using functions Standard Puppet way: function_name(argument) - each($variable) Ruby way - chaining argument.function_name - $variable.each
  18. 18. EPP Template engine Use Puppet $var instead of Ruby @var epp(filename) inline_epp(epp_string)
  19. 19. 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
  20. 20. 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
  21. 21. HEREDOC syntax check @(EOF:json) Can be used by e.g. Gepetto or any other Puppet plugin Built in : json $var = @(EOF:json) { “Puppet”: ‘awesome’ } - EOF
  22. 22. Types, Types, Types
  23. 23. Why do we need types? class ssh ( $server = true, ) { if $server { include ssh::server } } Parameterized class with parameter default
  24. 24. 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 !
  25. 25. 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)
  26. 26. 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
  27. 27. We need types! class ssh ( Boolean $server = true, ) { if $server { include ssh::server } } ! Types, Types, Types, Types
  28. 28. 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.
  29. 29. 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], ) { }
  30. 30. Available Types Integer[from, to] Float[from,to] Enum[*strings] Pattern[*patterns] Regexp[regexp] Boolean Array Hash
  31. 31. Deprecations
  32. 32. Deprecations Node inheritance Empty string comparison Variable naming Reference syntax Hyphens in names Ruby DSL
  33. 33. Node Inheritance node ‘basenode’ { include base include security } ! node ‘www.server.com’ inherits basenode { include webserver } # Dummy node as default ! ! ! ! # Real node inherits from basenode
  34. 34. Roles & Profiles node ‘www.server.com’ { include webserver } ! ! class basenode { include base include security } ! class webserver { include basenode } # No more node inheritance ! ! ! ! # Define a class instead
  35. 35. Empty string comparison An empty string compares to true instead of false
  36. 36. Empty string comparison $message = ‘’ ! if $message { notify { “Message: ${message}”: } } Empty string set as default ! Check for variable existing and having content
  37. 37. String comparison $ message = ‘’ ! if $message and $message != ‘’ { notify { “Message: ${message}”: } } Empty string set as default ! Check for variable existing and not empty string
  38. 38. Variable naming A variable may not start with a capital letter an underscore
  39. 39. Reference syntax Reference deprecation capital letter on title empty space between Type reference and title ! Class [Ssh] ! Class [‘ssh’] ! Class[‘ssh’] ! Deprecated capital title ! Empty space ! Working
  40. 40. Hyphens in names No more hyphens in module name class name define name
  41. 41. 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)
  42. 42. Ruby DSL Puppet 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
  43. 43. 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
  44. 44. The 4 Powers of Puppet 4
  45. 45. Performance Request response times and catalog compile times ! !
  46. 46. Scalability Switch on/off functionality for multi master setup ! ! !
  47. 47. Measurability
  48. 48. Flexibility Dealing with complex data natively in Puppet DSL
  49. 49. Upgrading to Puppet 4 Breaks old style Puppet DSL code Read documentation carefully Run tests
  50. 50. More information https://docs.puppetlabs.com/puppet/3.7/reference/ deprecated_language.html http://puppet-on-the-edge.blogspot.de/ https://github.com/puppetlabs/puppet-specifications
  51. 51. Text Support your modules Write PR, file bug reports, fix issues
  52. 52. Thank you Martin Alfke ! Co-Founder & CEO example42 GmbH i.G.

×