Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

PuppetConf 2016: Puppet 4.x: The Low WAT-tage Edition – Nick Fagerlund, Puppet

0 views

Published on

Here are the slides from Nick Fagerlund's PuppetConf 2016 presentation called PuppetConf 2016: Puppet 4.x: The Low WAT-tage Edition. Watch the videos at https://www.youtube.com/playlist?list=PLV86BgbREluVjwwt-9UL8u2Uy8xnzpIqa

Published in: Technology
  • Be the first to comment

PuppetConf 2016: Puppet 4.x: The Low WAT-tage Edition – Nick Fagerlund, Puppet

  1. 1. Puppet 4: The Low WAT-tage Edition Nick Fagerlund, Puppet
  2. 2. nickf@puppet.com @nfagerlund nfagerlund.net 2 Hi, I’m Nick Fagerlund!!!!
  3. 3. I’ve seen things you people wouldn’t believe My 2013 talk: https://www.youtube.com/watch?v=aU7vjKYqMUo My much smarter inspiration: https://www.destroyallsoftware.com/talks/wat 3
  4. 4. Agenda 4
  5. 5. Agenda 1. Fundamental Chaos 2. Slapstick 3. Elegance 5
  6. 6. 1. Fundamental Chaos 6
  7. 7. Relative Namespacing class profile::apache { include apache } 7
  8. 8. Relative Namespacing class profile::apache { class {'apache':} } 8
  9. 9. Relative Namespacing include apache meant… • <CURRENT NAMESPACE>::apache • <PARENT OF CURRENT NAMESPACE>::apache • etc. and so on • Eventually, ::apache https://projects.puppetlabs.com/issues/2053 https://tickets.puppetlabs.com/browse/PUP-121 9
  10. 10. Relative Namespacing class profile::apache { include ::apache } 10
  11. 11. Is Truth Beauty, and Beauty Truth? Facts: architecture => x86_64 domain => local facterversion => 2.4.2 fqdn => "treepie.local" gid => staff hardwareisa => i386 hardwaremodel => x86_64 hostname => treepie 11
  12. 12. Is Truth Beauty, and Beauty Truth? if $::is_virtual { # do something } 12
  13. 13. Is Truth Beauty, and Beauty Truth? “false” 13
  14. 14. Is Truth Beauty, and Beauty Truth? if $::is_virtual == 'true' { ... } # or: if str2bool($::is_virtual) { ... } # with the str2bool() function from puppetlabs/stdlib 14
  15. 15. Is Truth Beauty, and Beauty Truth? $interfaces = lo0,gif0,stf0,en0,en1,en2,p2p0,awdl0, bridge0,utun0 $macaddress_en0 = 72:00:04:eb:7a:93 ...etc. 15
  16. 16. 2. Slapstick 16
  17. 17. Data Type Nonsense $myvar = /^# @.*$/ notice($myvar) # Error: …Syntax error at '/' at /root/test.pp:1 17
  18. 18. Data Type Nonsense $one = 1 # String $one_times_one = 1*1 # Fixnum $an_undef = undef # NilClass $multi_undefs = [undef, undef] # Symbol (:undef) 18
  19. 19. Interpolation Shenanigans notice("Twenty plus eighty is ${20 + 80}.") # Error: left operand of + is not a number at /root/test.pp:15 19
  20. 20. Interpolation Shenanigans notice("Twenty plus eighty is ${'20' + 80}.") # Notice: Scope(Class[main]): Twenty plus eighty is 100. 20
  21. 21. Interpolation Shenanigans • Single bare word: • ${variable} • Bare word plus chained function call: • ${variable.split(‘,’)} • That’s it. Otherwise it’s an expression. 21
  22. 22. Inconsistent Comparisons notice( 'eat' == 'EAt' ) # true notice( 'eat' in 'EAten' ) # false 22
  23. 23. The Great Escape $greeting = 'How's it going?' 23
  24. 24. The Great Escape $s32path = 'C:WindowsSystem32' notice($s32path) # Error: Unclosed quote after '' in 'C:WindowsSystem32' 24
  25. 25. The Great Escape $s32path = 'C:WindowsSystem32' notice($s32path) # Notice: Scope(Class[main]): C:WindowsSystem32 >:c 25
  26. 26. The Great Escape $gitconfig = @("GITCONFIG"/L) [user] name = ${displayname} email = ${email} [alias] lg = "log —pretty=format:’%C(yellow)%h %C(reset) %s%C(cyan)%cr%C(reset) %C(blue)%an %C(reset) %C(green)%d%C(reset)’ --graph" | GITCONFIG 26
  27. 27. The Great Escape $s32path = @(MYPATH) C:WindowsSystem32 -MYPATH notice($s32path) # Notice: Scope(Class[main]): C:WindowsSystem32 27
  28. 28. Class Class class class { notify {'hey it worked':} } include class # Error: Syntax error at 'class' at /root/test.pp:5 28
  29. 29. Class Class class class { notify {'hey it worked':} } include "class" # Notice: hey it worked # Notice: /Stage[main]/Class/Notify[hey it worked]/message: defined 'message' as 'hey it worked' 29
  30. 30. Class Class class class { notify {'hey it worked':} } include "class" # Error: 'class' is not a valid classname at /Users/nick/Desktop/test.pp:1:7 30
  31. 31. 3. Elegance 31
  32. 32. Data Type Annotations class ntp ( $autoupdate = $ntp::params::autoupdate, $config = $ntp::params::config, $config_template = $ntp::params::config_template, $disable_monitor = $ntp::params::disable_monitor, $driftfile = $ntp::params::driftfile, $logfile = $ntp::params::logfile, $iburst_enable = $ntp::params::iburst_enable, $keys_enable = $ntp::params::keys_enable, $keys_file = $ntp::params::keys_file, $keys_controlkey = $ntp::params::keys_controlkey, $keys_requestkey = $ntp::params::keys_requestkey, $keys_trusted = $ntp::params::keys_trusted, $package_ensure = $ntp::params::package_ensure, $package_name = $ntp::params::package_name, $panic = $ntp::params::panic, $preferred_servers = $ntp::params::preferred_servers, $restrict = $ntp::params::restrict, $interfaces = $ntp::params::interfaces, $servers = $ntp::params::servers, $service_enable = $ntp::params::service_enable, $service_ensure = $ntp::params::service_ensure, $service_manage = $ntp::params::service_manage, $service_name = $ntp::params::service_name, $udlc = $ntp::params::udlc ) inherits ntp::params { ... 32 ... validate_absolute_path($config) validate_string($config_template) validate_bool($disable_monitor) validate_absolute_path($driftfile) if $logfile { validate_absolute_path($logfile) } validate_bool($iburst_enable) validate_bool($keys_enable) validate_re($keys_controlkey, ['^d+$', '']) validate_re($keys_requestkey, ['^d+$', '']) validate_array($keys_trusted) validate_string($package_ensure) validate_array($package_name) validate_bool($panic) validate_array($preferred_servers) validate_array($restrict) validate_array($interfaces) validate_array($servers) validate_bool($service_enable) validate_string($service_ensure) validate_bool($service_manage) validate_string($service_name) validate_bool($udlc)
  33. 33. Data Type Annotations ~~~~ 👀 ZOOM AND ENHANCE 👀 ~~~~ class ntp ( $config_template = $ntp::params::config_template, $disable_monitor = $ntp::params::disable_monitor, ... ) inherits ntp::params { ... validate_string($config_template) validate_bool($disable_monitor) 33
  34. 34. Data Type Annotations class ntp ( Boolean $disable_monitor = $ntp::params::disable_monitor, Pattern[/^d+$/] $keys_controlkey = $ntp::params::keys_controlkey, Integer $keys_requestkey = $ntp::params::keys_requestkey, Array $keys_trusted = $ntp::params::keys_trusted, String $package_ensure = $ntp::params::package_ensure, 34
  35. 35. Iteration •Old Ruby DSL? •Do-nothing defined types? •create_resources function? 35
  36. 36. Data Type Annotations # in Hiera data: admin_users: casey: uid: '1330' gid: allstaff shell: zsh groups: - developers - release leslie: uid: '1308' gid: allstaff groups: - prosvc 36 # in Puppet manifest: class puppet_ops::users::virtual { create_resources( '@user', lookup('admin_users'), { # defaults ensure => present, purge_ssh_keys => true, } ) }
  37. 37. Iteration $binaries = ['facter', 'hiera', 'mco', ‘puppet', 'puppetserver'] $binaries.each |String $binary| { file { "/usr/bin/${binary}": ensure => link, target => "/opt/puppetlabs/bin/${binary}", } } 37
  38. 38. EPP Templates <%- | Boolean $keys_enable, String $keys_file, Array $keys_trusted, String $keys_requestkey, String $keys_controlkey | -%> <%# Parameter tag ↑ -%> <%# Non-printing tag ↓ -%> <% if $keys_enable { -%> <%# Expression-printing tag ↓ -%> keys <%= $keys_file %> 38 <% unless $keys_trusted =~ Array[Data,0,0] { -%> trustedkey <%= $keys_trusted.join(' ') %> <% } -%> <% if $keys_requestkey =~ String[1] { -%> requestkey <%= $keys_requestkey %> <% } -%> <% if $keys_controlkey =~ String[1] { -%> controlkey <%= $keys_controlkey %> <% } -%> <% } -%>
  39. 39. Thanks 39
  40. 40. Questions? nickf@puppet.com @nfagerlund nfagerlund.net 40

×