Reader small image

You're reading from  Puppet 8 for DevOps Engineers

Product typeBook
Published inJun 2023
PublisherPackt
ISBN-139781803231709
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
David Sandilands
David Sandilands
author image
David Sandilands

David Sandilands is a principal solutions architect at Puppet, with a focus on the product management of Puppet's development ecosystem and integrations. This includes management of the Forge, supported modules, the Puppet Developer Kit, and integrations such as ServiceNow and Splunk. Before this, David worked within Puppet's solutions architect team, helping Puppet's largest customers deliver infrastructure automation at scale, and supported these customers in their DevOps working practices. He spent eight years at NatWest as a cloud infrastructure engineer delivering their IaaS platform. Based in Falkirk, Scotland, David has a Bachelor of Engineering in computer science from the University of Edinburgh.
Read more about David Sandilands

Right arrow

Conditional statements

Puppet has the conditional statements you would expect of any language, with if, unless, and case allowing code behavior to be different depending on things such as facts or data from external sources. Puppet additionally uses selectors, which are similar to a case statement but return a value instead of executing code on result.

If and unless statements

The if statement follows a specific syntax that includes the if keyword followed by a condition, an opening curly brace ({), the Puppet code to execute if the condition evaluates to true, and a closing curly brace (}).

The following example is a simple check on a Boolean in example_bool to print a notice if it contains true:

if $example_bool {
  notice 'It was true'
}

This can be optionally extended by adding an else keyword after the closing curly brace (}) of the if statement and then using an opening curly brace ({) with Puppet code to perform if the condition is false. This...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Puppet 8 for DevOps Engineers
Published in: Jun 2023Publisher: PacktISBN-13: 9781803231709

Author (1)

author image
David Sandilands

David Sandilands is a principal solutions architect at Puppet, with a focus on the product management of Puppet's development ecosystem and integrations. This includes management of the Forge, supported modules, the Puppet Developer Kit, and integrations such as ServiceNow and Splunk. Before this, David worked within Puppet's solutions architect team, helping Puppet's largest customers deliver infrastructure automation at scale, and supported these customers in their DevOps working practices. He spent eight years at NatWest as a cloud infrastructure engineer delivering their IaaS platform. Based in Falkirk, Scotland, David has a Bachelor of Engineering in computer science from the University of Edinburgh.
Read more about David Sandilands