Functions in Puppet context

0 votes
What are functions in puppet?
Jul 24, 2019 in Puppet by Namik
• 1,230 points
1,106 views

1 answer to this question.

0 votes

Functions are plug-ins, written in Ruby, that you can call during catalog compilation. A call to any function is an expression that resolves to a value. Most functions accept one or more values as arguments, and return a resulting value.

Puppet supports functions.It supports two types of functions known with the name of statement and rvalue functions.

  • Statements stand on their own and they do not have any return type. They are used for performing standalone tasks like importing other Puppet modules in the new manifest file.
  • Rvalue returns values and can only be used when the statement requires a value, such as an assignment or a case statement.

You can write your own functions in the Puppet language to transform data and construct values. A function can optionally take one or more parameters as arguments. A function returns a calculated value from its final expression.

Function Syntax in Puppet: 

function <MODULE NAME>::<NAME>(<PARAMETER LIST>) >> <RETURN TYPE> {  ... body of function ...  final expression, which will be the returned value of the function}

Function Example in Puppet: 

function apache::bool2http(Variant[String, Boolean] $arg) >> String {  case $arg {    false, undef, /(?i:false)/ : { 'Off' }    true, /(?i:true)/          : { 'On' }    default               : { "$arg" }  }}
answered Jul 24, 2019 by Sirajul
• 59,230 points

Related Questions In Puppet

0 votes
1 answer
0 votes
1 answer

Service already defines error in Puppet

Hey @Rohan, try this: class MyClass { ...READ MORE

answered Feb 9, 2019 in Puppet by Monish
1,120 views
0 votes
1 answer

What are profiles in Puppet?

Wrapper classes that use multiple component modules ...READ MORE

answered Feb 15, 2019 in Puppet by Sheela
637 views
0 votes
1 answer

Can I access environment variables with Facter in Puppet?

Hey @Ruth, not directly. However, Facter reads ...READ MORE

answered Feb 15, 2019 in Puppet by Krishti

edited Feb 15, 2019 3,658 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,040 views
+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer

What is PSON in puppet and how is it different from JSON?

PSON is a variant of JSON which ...READ MORE

answered Jul 24, 2019 in Puppet by Sirajul
• 59,230 points
2,186 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP