Local scopes
Code inside a class definition, defined type, or lambda exists in a local scope.
Variables and defaults declared in a local scope are only available in that scope and its children. There are two different sets of rules for when scopes are considered related. For more information, see scope lookup rules.
In this example, a local scope can see out into node and top scope, but outer scopes cannot see in:
# /etc/puppetlabs/code/modules/scope_example/manifests/init.pp class scope_example { $variable = "Hi!" notify {"Message from here: $variable":} notify {"Node scope: $node_variable Top scope: $top_variable":} } # /etc/puppetlabs/code/environments/production/manifests/site.pp $top_variable = "Available!" node 'puppet.example.com' { $node_variable = "Available!" include scope_example notify {"Message from node scope: $variable":} } notify {"Message from top scope: $variable":}
$ puppet apply site.pp notice: Message from here: Hi! notice: Node scope: Available! Top scope: Available! notice: Message from node scope: notice: Message from top scope: