puppetconf 2016: puppet 4.x: the low wat-tage edition – nick fagerlund, puppet

41
Puppet 4: The Low WAT-tage Edition Nick Fagerlund, Puppet

Upload: puppet

Post on 10-Jan-2017

53 views

Category:

Technology


0 download

TRANSCRIPT

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

Puppet 4: The Low WAT-tage Edition

Nick Fagerlund, Puppet

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

[email protected] @nfagerlund

nfagerlund.net

2

Hi, I’m Nick Fagerlund!!!!

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

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

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

Agenda

4

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

Agenda

1. Fundamental Chaos 2. Slapstick 3. Elegance

5

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

1. Fundamental Chaos

6

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

Relative Namespacing

class profile::apache { include apache }

7

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

Relative Namespacing

class profile::apache { class {'apache':} }

8

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

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

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

Relative Namespacing

class profile::apache { include ::apache }

10

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

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

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

Is Truth Beauty, and Beauty Truth?

if $::is_virtual { # do something }

12

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

Is Truth Beauty, and Beauty Truth?

“false”

13

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

Is Truth Beauty, and Beauty Truth?

if $::is_virtual == 'true' { ... } # or: if str2bool($::is_virtual) { ... } # with the str2bool() function from puppetlabs/stdlib

14

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

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

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

2. Slapstick

16

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

Data Type Nonsense

$myvar = /^# @.*$/ notice($myvar)

# Error: …Syntax error at '/' at /root/test.pp:1

17

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

Data Type Nonsense

$one = 1 # String $one_times_one = 1*1 # Fixnum $an_undef = undef # NilClass $multi_undefs = [undef, undef] # Symbol (:undef)

18

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

Interpolation Shenanigans

notice("Twenty plus eighty is ${20 + 80}.")

# Error: left operand of + is not a number at /root/test.pp:15

19

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

Interpolation Shenanigans

notice("Twenty plus eighty is ${'20' + 80}.")

# Notice: Scope(Class[main]): Twenty plus eighty is 100.

20

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

Interpolation Shenanigans

• Single bare word: • ${variable}

• Bare word plus chained function call: • ${variable.split(‘,’)}

• That’s it. Otherwise it’s an expression.

21

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

Inconsistent Comparisons

notice( 'eat' == 'EAt' ) # true notice( 'eat' in 'EAten' ) # false

22

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

The Great Escape

$greeting = 'How\'s it going?'

23

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

The Great Escape

$s32path = 'C:\Windows\System32\' notice($s32path)

# Error: Unclosed quote after '' in 'C:\Windows\System32\'

24

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

The Great Escape

$s32path = 'C:\Windows\System32\\' notice($s32path)

# Notice: Scope(Class[main]): C:\Windows\System32\\

>:c

25

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

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

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

The Great Escape

$s32path = @(MYPATH) C:\Windows\System32\ -MYPATH notice($s32path)

# Notice: Scope(Class[main]): C:\Windows\System32\

27

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

Class Class

class class { notify {'hey it worked':} }

include class # Error: Syntax error at 'class' at /root/test.pp:5

28

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

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

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

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

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

3. Elegance

31

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

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)

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

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

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

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

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

Iteration

•Old Ruby DSL? •Do-nothing defined types? •create_resources function?

35

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

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, } ) }

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

Iteration

$binaries = ['facter', 'hiera', 'mco', ‘puppet', 'puppetserver']

$binaries.each |String $binary| { file { "/usr/bin/${binary}": ensure => link, target => "/opt/puppetlabs/bin/${binary}", } }

37

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

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 %> <% } -%> <% } -%>

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

Thanks

39

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

[email protected]

@nfagerlund nfagerlund.net

40

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