Variables
Variables are denoted by a $
prefix and can be declared as arrays or hashes. They can be scoped locally
to a class or globally if declared outside a class. Class-scoped variables
are also available publicly by qualifying their parent class:
class classone { $variableone = 'test' $variabletwo = [ 'foo', 'bar', 'baz', 'qux' ] $variablethree = { foo => 'bar', baz => 'qux' } } class classtwo { $variableone = $classone::variableone $variabletwo = $classone::variabletwo[1] $variablethree = $classtwo::variablethree[foo] }
This can be useful in some circumstances, but it is somewhat difficult to ensure predictable behavior, as the values are dependent on the order of evaluation of the two classes. If you need to use a variable from one class in another, be sure that you can guarantee the order in which they are evaluated.
Note
Puppet also supports an extensive set of comparison and arithmetic operators (even Backus-Naur Form!) for expressions as variable values. See the Puppet language guide at http://docs.puppetlabs.com/guides/language_guide.html for complete documentation.
Get Managing Infrastructure with Puppet now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.