SlideShare a Scribd company logo
1 of 67
Download to read offline
Yamata 
no 
Orochi
Puppet 
Language 
4.0 
henrik.lindberg@puppetlabs.com
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
Puppet 
4.0 
• Language 
Cleanup 
– Sanity, 
Principle 
of 
Least 
Surprise 
– Expressions, 
Expressions, 
Expressions 
• Features 
– Misc 
enhancements 
– Resource 
Expression 
Features 
– IteraGon 
– Type 
System 
/ 
OpGonal 
Typing 
– Embedded 
Puppet 
Templates 
(EPP) 
– Heredoc
Cleanup 
• Language 
SpecificaGon 
– 
yes 
we 
have 
one 
– hQps://github.com/puppetlabs/puppet-­‐specificaGons 
• Numbers 
are 
Numbers 
• No 
magic 
to-­‐string 
for 
=~ !~ in 
• Upper 
case 
bare 
words 
are 
Type 
References 
• Empty 
string 
is 
not 
undef 
(and 
thus 
"thruty") 
• InterpolaGon 
follows 
specified 
rules 
• +=, 
[]= 
removed, 
no 
more 
mutaGon
Misc 
new 
features 
1(7) 
• 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}
Misc 
new 
features 
2(7) 
• Append 
to 
Array 
with 
<< 
[1,2,3] << 4 => [1,2,3,4] 
[1,2,3] << [4,5,6] => [1,2,3,[4,5,6]]
Misc 
new 
features 
3(7) 
• Unfold 
with 
unary 
* 
$a = [2,3] 
$b = [1, *$a, 4] => [1,2,3,4] 
• Unfold 
in 
case 
opGon, 
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]
Misc 
new 
features 
4(7) 
• Substring 
in 
string 
'cd' in "abcde" => true 
• Substring 
with 
[] 
"xyzabcdef"[3,3] => "abc" 
"xyzabcdef"[3] => "a" 
"xyzabcdef"[3,-2] => "abcde"
Misc 
new 
features 
5(7) 
• Matches 
with 
Regexp 
in 
String 
form 
$a = "example.com" 
$url =~ "http://$a.*"
Misc 
new 
features 
6(7) 
• Detailed 
Error 
Messages 
– SemanGc 
validaGon 
unless 
lex 
or 
syntax 
errors 
– Outputs 
posiGon 
on 
line 
– Can 
report 
more 
than 
one 
error
Expression 
Based 
Grammar 
6(7) 
• if, 
unless, 
case 
are 
expressions 
notice if 1 > 2 { true } else { false } 
# => false 
$a = 
case 2 { 
1, 2, 3: { yes } 
default: { no } 
} 
# => $a == yes
Resource 
Expression
Local 
Defaults 
file { 
default: 
mode => '444', 
owner => 'admin'; 
title: 
. . . ; 
}
Unfold 
Hash 
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 
funcGons 
taking 
callable 
code 
blocks 
(lambdas) 
= 
open 
design 
• Calls 
can 
now 
be 
expressed 
from 
leh 
to 
right 
using 
'.' 
notaGon
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 
iteraGon 
• Returns 
transformed 
result 
[1,2,3].reduce |$result, $x| { 
$result + $x 
} 
=> 6
And 
more
E-­‐I-­‐E-­‐I-­‐O
E-­‐I-­‐E-­‐I-­‐O
E-­‐I-­‐E-­‐I-­‐O
E-­‐I-­‐E-­‐I-­‐O
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 
familiar 
from 
Resource 
– 
i.e. 
Class, 
File, 
User, 
where 
[ 
] 
applied 
to 
the 
type 
makes 
it 
more 
specific 
– 
e.g. 
File['foo']
Example 
Integer 
# All integers 
Integer 
# All integers >=42 
Integer[42] 
# All integers >=42 and <=142 
Integer[42,142]
AutomaGc 
type 
checking! 
define mytype(Integer[80,443] $port){ 
# port guaranteed to be integer 
# and between 80 and 443 
# otherwise an error 
}
More 
advanced 
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
OperaGons 
on 
Type 
• Since 
a 
Type 
is 
a 
kind 
of 
PaQern… 
– 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
Type 
Hierarchy 
Any 
|- Scalar 
| |- Numeric 
| | |- Integer[from, to] 
| | |- Float[from, to] 
| | 
| |- String[from, to] 
| | |- Enum[*strings] 
| | |- Pattern[*patterns] 
| | 
| |- Boolean 
| |- Regexp[pattern_string]
Type 
Hierarchy 
Any 
|- Collection 
| |- Array[T] 
| | |- Tuple[T*, from, to] 
| | 
| |- Hash[K, V] 
| | |- Struct[{ key => T, ...}] 
| 
|- Variant[T*] 
|- Optional[T] 
| 
|- Undef 
|- Default 
| 
|- Type[T]
Type 
Hierarchy 
Any 
|- CatalogEntry 
| |- Resource[type_name, title] 
| |- Class[class_name] 
| 
|- Undef 
|- Data 
| |- Scalar 
| |- Array[Data] 
| |- Hash[Scalar, Data] 
| |- Undef
EPP
EPP 
– 
Templates 
in 
Puppet 
• Same 
template 
markup 
as 
ERB 
– Logic 
is 
Puppet 
instead 
of 
Ruby 
AND 
• Can 
be 
parameterized 
! 
• Use 
funcGons 
epp(template) 
inline_epp(string) 
• instead 
of 
template() 
inline_template()
Example 
EPP 
$x = 'human' 
inline_epp('This is not the <%= $x %> you are looking 
for.') 
# => 'This is not the human you are looking for.' 
$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.
Heredoc
Puppet 
Heredoc 
• For 
more 
detailed 
control 
over 
a 
block 
of 
text 
• No, 
or 
selected 
set 
of 
escapes 
• InterpolaGon 
or 
no 
interpolaGon 
• Can 
be 
syntax 
checked 
by 
parser 
(JSon 
in 
core, 
can 
add 
plugin 
language 
support) 
• Control 
over 
leh 
margin
Heredoc 
-­‐ 
Syntax 
ENDS-­‐HERE 
anything 
not 
in 
<text> 
"ENDS-­‐HERE" 
with 
interpola:on 
:json 
syntax 
check 
result 
/tsrn$L 
turns 
on 
escape 
/ 
turns 
on 
all 
@( ["]<endtag>["] [:<syntax>] [/<escapes>] ) 
<text> 
[|][-] <endtag> 
| 
set 
le= 
margin 
-­‐ 
trim 
trailing 
t 
tab 
s 
space 
r 
return 
n 
new-­‐line 
$ 
$ 
L 
<end 
of 
line>
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
Ruby 
API
Ruby 
API 
• 4x 
FuncGon 
API 
– type 
checked 
– dispatch 
to 
impl 
based 
on 
given 
types 
– more 
powerful 
– safer 
• Binder 
– composable 
type 
safe 
injecGon 
– for 
plugins 
and 
data 
(e.g. 
syntax 
checkers)
Summary 
• Language 
Cleanup 
• More 
strict 
• New 
Features 
• BeQer 
Error 
Messages 
• IteraGon 
• Type 
System 
• Puppet 
Templates 
– 
EPP 
• Heredoc
In 
pracGce 
• Run 
now 
with 
–parser 
future 
• Fix 
deprecaGons 
and 
issues 
• Make 
backwards 
compaGble 
changes 
and 
conGnue 
in 
producGon 
on 
3x 
• Test 
carefully 
and 
conGnue 
running 
on 
what 
will 
be 
Puppet 
4.0 
• 4.0 
expected 
release 
before 
end 
of 
the 
year
Links 
• github/puppetlabs/puppet-­‐specificaGons 
• hQp://puppet-­‐on-­‐the-­‐edge.blogspot.com/ 
• TwiQer 
@hel 
• IRC 
helindbe

More Related Content

What's hot

Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Python Usage (5-minute-summary)
Python Usage (5-minute-summary)
Ohgyun Ahn
 
Functions in python
Functions in pythonFunctions in python
Functions in python
Ilian Iliev
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
Software Guru
 
Nik Graf - Get started with Reason and ReasonReact
Nik Graf - Get started with Reason and ReasonReactNik Graf - Get started with Reason and ReasonReact
Nik Graf - Get started with Reason and ReasonReact
OdessaJS Conf
 

What's hot (20)

Unit vii wp ppt
Unit vii wp pptUnit vii wp ppt
Unit vii wp ppt
 
Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Python Usage (5-minute-summary)
Python Usage (5-minute-summary)
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Learn python - for beginners - part-2
Learn python - for beginners - part-2Learn python - for beginners - part-2
Learn python - for beginners - part-2
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) Services
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Python Puzzlers - 2016 Edition
Python Puzzlers - 2016 EditionPython Puzzlers - 2016 Edition
Python Puzzlers - 2016 Edition
 
Nik Graf - Get started with Reason and ReasonReact
Nik Graf - Get started with Reason and ReasonReactNik Graf - Get started with Reason and ReasonReact
Nik Graf - Get started with Reason and ReasonReact
 
1 the ruby way
1   the ruby way1   the ruby way
1 the ruby way
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP Arrays
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
Perl_Tutorial_v1
Perl_Tutorial_v1Perl_Tutorial_v1
Perl_Tutorial_v1
 
Groovy unleashed
Groovy unleashed Groovy unleashed
Groovy unleashed
 

Viewers also liked

To the Future! - Goals for Puppet 4 - PuppetConf 2014
To the Future! - Goals for Puppet 4 - PuppetConf 2014To the Future! - Goals for Puppet 4 - PuppetConf 2014
To the Future! - Goals for Puppet 4 - PuppetConf 2014
Puppet
 
Introduction to Puppet Enterprise 2016.2
Introduction to Puppet Enterprise 2016.2Introduction to Puppet Enterprise 2016.2
Introduction to Puppet Enterprise 2016.2
Puppet
 

Viewers also liked (12)

Luke Kanies Keynote: Nearly a Decade of Puppet: What We've Learned and Where ...
Luke Kanies Keynote: Nearly a Decade of Puppet: What We've Learned and Where ...Luke Kanies Keynote: Nearly a Decade of Puppet: What We've Learned and Where ...
Luke Kanies Keynote: Nearly a Decade of Puppet: What We've Learned and Where ...
 
To the Future! - Goals for Puppet 4 - PuppetConf 2014
To the Future! - Goals for Puppet 4 - PuppetConf 2014To the Future! - Goals for Puppet 4 - PuppetConf 2014
To the Future! - Goals for Puppet 4 - PuppetConf 2014
 
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
 
Puppet evolutions
Puppet evolutionsPuppet evolutions
Puppet evolutions
 
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
 
The Puppet Master on the JVM - PuppetConf 2014
The Puppet Master on the JVM - PuppetConf 2014The Puppet Master on the JVM - PuppetConf 2014
The Puppet Master on the JVM - PuppetConf 2014
 
Killer R10K Workflow - PuppetConf 2014
Killer R10K Workflow - PuppetConf 2014Killer R10K Workflow - PuppetConf 2014
Killer R10K Workflow - PuppetConf 2014
 
Test Driven Development with Puppet - PuppetConf 2014
Test Driven Development with Puppet - PuppetConf 2014Test Driven Development with Puppet - PuppetConf 2014
Test Driven Development with Puppet - PuppetConf 2014
 
Introduction to Puppet Enterprise 2016.2
Introduction to Puppet Enterprise 2016.2Introduction to Puppet Enterprise 2016.2
Introduction to Puppet Enterprise 2016.2
 
PuppetConf 2016: The Truth, Nothing but the Truth: Why Type Systems are Impor...
PuppetConf 2016: The Truth, Nothing but the Truth: Why Type Systems are Impor...PuppetConf 2016: The Truth, Nothing but the Truth: Why Type Systems are Impor...
PuppetConf 2016: The Truth, Nothing but the Truth: Why Type Systems are Impor...
 
Migrating to Puppet 4.0
Migrating to Puppet 4.0Migrating to Puppet 4.0
Migrating to Puppet 4.0
 
External Data in Puppet 4
External Data in Puppet 4External Data in Puppet 4
External Data in Puppet 4
 

Similar to Puppet Language 4.0 - PuppetConf 2014

PowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdfPowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdf
outcast96
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
Lei Kang
 
Python language data types
Python language data typesPython language data types
Python language data types
Harry Potter
 
Python language data types
Python language data typesPython language data types
Python language data types
Young Alista
 
Python language data types
Python language data typesPython language data types
Python language data types
Luis Goldster
 
Python language data types
Python language data typesPython language data types
Python language data types
Tony Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data types
Fraboni Ec
 

Similar to Puppet Language 4.0 - PuppetConf 2014 (20)

Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in ruby
 
Data Pipelines in Swift
Data Pipelines in SwiftData Pipelines in Swift
Data Pipelines in Swift
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
 
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
 
PowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdfPowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdf
 
Rakudo
RakudoRakudo
Rakudo
 
Functional Operations - Susan Potter
Functional Operations - Susan PotterFunctional Operations - Susan Potter
Functional Operations - Susan Potter
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcional
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 

More from Puppet

Puppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepo
Puppet
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)
Puppet
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automation
Puppet
 

More from Puppet (20)

Puppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepo
 
Puppetcamp r10kyaml
Puppetcamp r10kyamlPuppetcamp r10kyaml
Puppetcamp r10kyaml
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)
 
Puppet camp vscode
Puppet camp vscodePuppet camp vscode
Puppet camp vscode
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twenties
 
Applying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codeApplying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance code
 
KGI compliance as-code approach
KGI compliance as-code approachKGI compliance as-code approach
KGI compliance as-code approach
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automation
 
Keynote: Puppet camp compliance
Keynote: Puppet camp complianceKeynote: Puppet camp compliance
Keynote: Puppet camp compliance
 
Automating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowAutomating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNow
 
Puppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet: The best way to harden Windows
Puppet: The best way to harden Windows
 
Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020
 
Accelerating azure adoption with puppet
Accelerating azure adoption with puppetAccelerating azure adoption with puppet
Accelerating azure adoption with puppet
 
Puppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael Pinson
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin Reeuwijk
 
Take control of your dev ops dumping ground
Take control of your  dev ops dumping groundTake control of your  dev ops dumping ground
Take control of your dev ops dumping ground
 
100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software
 
Puppet User Group
Puppet User GroupPuppet User Group
Puppet User Group
 
Continuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsContinuous Compliance and DevSecOps
Continuous Compliance and DevSecOps
 
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyThe Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
 

Recently uploaded

TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Puppet Language 4.0 - PuppetConf 2014

  • 1.
  • 3.
  • 4.
  • 5.
  • 6. Puppet Language 4.0 henrik.lindberg@puppetlabs.com
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. 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
  • 12.
  • 13. Puppet 4.0 • Language Cleanup – Sanity, Principle of Least Surprise – Expressions, Expressions, Expressions • Features – Misc enhancements – Resource Expression Features – IteraGon – Type System / OpGonal Typing – Embedded Puppet Templates (EPP) – Heredoc
  • 14. Cleanup • Language SpecificaGon – yes we have one – hQps://github.com/puppetlabs/puppet-­‐specificaGons • Numbers are Numbers • No magic to-­‐string for =~ !~ in • Upper case bare words are Type References • Empty string is not undef (and thus "thruty") • InterpolaGon follows specified rules • +=, []= removed, no more mutaGon
  • 15.
  • 16. Misc new features 1(7) • 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}
  • 17. Misc new features 2(7) • Append to Array with << [1,2,3] << 4 => [1,2,3,4] [1,2,3] << [4,5,6] => [1,2,3,[4,5,6]]
  • 18. Misc new features 3(7) • Unfold with unary * $a = [2,3] $b = [1, *$a, 4] => [1,2,3,4] • Unfold in case opGon, 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]
  • 19. Misc new features 4(7) • Substring in string 'cd' in "abcde" => true • Substring with [] "xyzabcdef"[3,3] => "abc" "xyzabcdef"[3] => "a" "xyzabcdef"[3,-2] => "abcde"
  • 20. Misc new features 5(7) • Matches with Regexp in String form $a = "example.com" $url =~ "http://$a.*"
  • 21. Misc new features 6(7) • Detailed Error Messages – SemanGc validaGon unless lex or syntax errors – Outputs posiGon on line – Can report more than one error
  • 22. Expression Based Grammar 6(7) • if, unless, case are expressions notice if 1 > 2 { true } else { false } # => false $a = case 2 { 1, 2, 3: { yes } default: { no } } # => $a == yes
  • 24. Local Defaults file { default: mode => '444', owner => 'admin'; title: . . . ; }
  • 25. Unfold Hash file { default: * => $defaults_hash; 'tmp/foo': mode => '666', * => $params_hash; }
  • 26. Create Resources Equiv. in Puppet Resource[$type] { default: * => $defaults_hash; $titles: * => $params_hash; }
  • 27.
  • 28. LOOOOOOOPS • Iterate over: – Arrays – Hashes – Strings – Integer ranges • Implemented as funcGons taking callable code blocks (lambdas) = open design • Calls can now be expressed from leh to right using '.' notaGon
  • 29. each • Do something with each element • Returns LHS [1,2,3].each |$x| { notice $x } each([1,2,3]) |$x| { notice $x }
  • 30. map • Transform each element • Returns transformed result [1,2,3].map |$x| { $x*10 } => [10,20,30]
  • 31. filter • Produces elements that match • Returns filtered result [1,2,3].filter|$x| { $x >= 2 } => [2,3]
  • 32. reduce • Transforms / reduces many to one • Feeds seed/previous result into next iteraGon • Returns transformed result [1,2,3].reduce |$result, $x| { $result + $x } => 6
  • 34.
  • 35.
  • 36.
  • 38.
  • 40.
  • 42.
  • 43.
  • 45.
  • 46. The Puppet Type System Cow Integer
  • 47. 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']
  • 48. Example Integer # All integers Integer # All integers >=42 Integer[42] # All integers >=42 and <=142 Integer[42,142]
  • 49. AutomaGc type checking! define mytype(Integer[80,443] $port){ # port guaranteed to be integer # and between 80 and 443 # otherwise an error }
  • 50. More advanced 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
  • 51. OperaGons on Type • Since a Type is a kind of PaQern… – 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
  • 52. Type Hierarchy Any |- Scalar | |- Numeric | | |- Integer[from, to] | | |- Float[from, to] | | | |- String[from, to] | | |- Enum[*strings] | | |- Pattern[*patterns] | | | |- Boolean | |- Regexp[pattern_string]
  • 53. Type Hierarchy Any |- Collection | |- Array[T] | | |- Tuple[T*, from, to] | | | |- Hash[K, V] | | |- Struct[{ key => T, ...}] | |- Variant[T*] |- Optional[T] | |- Undef |- Default | |- Type[T]
  • 54. Type Hierarchy Any |- CatalogEntry | |- Resource[type_name, title] | |- Class[class_name] | |- Undef |- Data | |- Scalar | |- Array[Data] | |- Hash[Scalar, Data] | |- Undef
  • 55. EPP
  • 56. EPP – Templates in Puppet • Same template markup as ERB – Logic is Puppet instead of Ruby AND • Can be parameterized ! • Use funcGons epp(template) inline_epp(string) • instead of template() inline_template()
  • 57. Example EPP $x = 'human' inline_epp('This is not the <%= $x %> you are looking for.') # => 'This is not the human you are looking for.' $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.
  • 59. Puppet Heredoc • For more detailed control over a block of text • No, or selected set of escapes • InterpolaGon or no interpolaGon • Can be syntax checked by parser (JSon in core, can add plugin language support) • Control over leh margin
  • 60. Heredoc -­‐ Syntax ENDS-­‐HERE anything not in <text> "ENDS-­‐HERE" with interpola:on :json syntax check result /tsrn$L turns on escape / turns on all @( ["]<endtag>["] [:<syntax>] [/<escapes>] ) <text> [|][-] <endtag> | set le= margin -­‐ trim trailing t tab s space r return n new-­‐line $ $ L <end of line>
  • 61. 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
  • 63. Ruby API • 4x FuncGon API – type checked – dispatch to impl based on given types – more powerful – safer • Binder – composable type safe injecGon – for plugins and data (e.g. syntax checkers)
  • 64. Summary • Language Cleanup • More strict • New Features • BeQer Error Messages • IteraGon • Type System • Puppet Templates – EPP • Heredoc
  • 65. In pracGce • Run now with –parser future • Fix deprecaGons and issues • Make backwards compaGble changes and conGnue in producGon on 3x • Test carefully and conGnue running on what will be Puppet 4.0 • 4.0 expected release before end of the year
  • 66.
  • 67. Links • github/puppetlabs/puppet-­‐specificaGons • hQp://puppet-­‐on-­‐the-­‐edge.blogspot.com/ • TwiQer @hel • IRC helindbe