-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Puppet 8 for DevOps Engineers
By :

In this section, we will cover how to use variables in Puppet and how this differs from other procedural languages. The key thing to understand about Puppet variables is that they are only assigned once during compilation in a given scope. In a traditional procedural language, it’s common to use variables throughout your code, where you might gather the current state as your code runs, use variables to keep track of it, and update it to act and make procedural decisions at various stages of your code. The following is an example of a simple PowerShell script that runs a command several times and adds the output to a single variable. It does so by using select-string
to search for files containing ?
in the .sh
and .pp
files in the user’s code directory:
$Matches = Select-String -Path "$PSHOME\code\*.sh" -Pattern '\? … … $Matches = $Matches + Select-String -Path "$PSHOME\code\*.pp" -Pattern '\?
This state check...