Variable scoping
bogotobogo.com site search:
Puppet
Puppet with Amazon AWS I - Puppet accounts
Puppet with Amazon AWS II (ssh & puppetmaster/puppet install)
Puppet with Amazon AWS III - Puppet running Hello World
Puppet Code Basics - Terminology
Puppet with Amazon AWS on CentOS 7 (I) - Master setup on EC2
Puppet with Amazon AWS on CentOS 7 (II) - Configuring a Puppet Master Server with Passenger and Apache
Puppet master /agent ubuntu 14.04 install on EC2 nodes
Puppet master post install tasks - master's names and certificates setup,
Puppet agent post install tasks - configure agent, hostnames, and sign request
EC2 Puppet master/agent basic tasks - main manifest with a file resource/module and immediate execution on an agent node
Setting up puppet master and agent with simple scripts on EC2 / remote install from desktop
EC2 Puppet - Install lamp with a manifest ('puppet apply')
EC2 Puppet - Install lamp with a module
Puppet variable scope
Puppet packages, services, and files
Puppet packages, services, and files II with nginx
Puppet templates
Puppet creating and managing user accounts with SSH access
Puppet Locking user accounts & deploying sudoers file
Puppet exec resource
Puppet classes and modules
Puppet Forge modules
Puppet Express
Puppet Express 2
Puppet 4 : Changes
Puppet --configprint
Puppet with Docker
Puppet 6.0.2 install on Ubuntu 18.04
In Puppet, the combined configuration to be applied to a host is called a catalog, and the process of applying it is called a run.
The Puppet client software is called the agent. Puppet calls the definition of the
host itself a node. The Puppet server is called the master.
Variable scoping
Suppose we've decided to configure some variables in our nodes, as an example below:
node 'puppet.bogotobogo.com'
{
$v = 'a'
...
$v = 'b'
}
The $v variable would start out with a value of 'a' and then, when it
was next assigned, it would change to a value of 'b'. In Puppet, these same two statements cause an error:
err: Cannot reassign variable v at /etc/puppet/manifests/node.pp:3
What happened? Puppet is a declarative language. Allowing variable reassignment would require us to rely
on order in the file to determine the value of the variable, and order does not matter in a declarative language. The
principal outcome of this is that we cannot redefine a variable inside the same scope as shown our node definition above.
So what's a scope? Each class or node introduces a new scope.
Four scopes are available: top scope, node scope, parent scope, and local scope.
- Top scope is anything declared in site.pp or imported manifests. Top scope
can be explicitly accessed by prepending :: to a variable. It is best practice to write fact variables as $::var so
as to use the fact at top scope, thus preventing the variable from being overwritten anywhere.
- Node scope is the scope created by the enclosing brackets of a node definition. Node scope is unfortunately anonymous, so there is no way
to explicitly retrieve it. A variable set at node scope will still be available in local scope unless it is overridden at local
scope or parent scope.
- Local scope is the scope of a single class or defined type.
- Parent scope is the scope of a class that is explicitly inherited through use of the inherits keyword. The parent scope is the scope
of a class that is explicitly inherited through use of the inherits keyword
Puppet
Puppet with Amazon AWS I - Puppet accounts
Puppet with Amazon AWS II (ssh & puppetmaster/puppet install)
Puppet with Amazon AWS III - Puppet running Hello World
Puppet Code Basics - Terminology
Puppet with Amazon AWS on CentOS 7 (I) - Master setup on EC2
Puppet with Amazon AWS on CentOS 7 (II) - Configuring a Puppet Master Server with Passenger and Apache
Puppet master /agent ubuntu 14.04 install on EC2 nodes
Puppet master post install tasks - master's names and certificates setup,
Puppet agent post install tasks - configure agent, hostnames, and sign request
EC2 Puppet master/agent basic tasks - main manifest with a file resource/module and immediate execution on an agent node
Setting up puppet master and agent with simple scripts on EC2 / remote install from desktop
EC2 Puppet - Install lamp with a manifest ('puppet apply')
EC2 Puppet - Install lamp with a module
Puppet variable scope
Puppet packages, services, and files
Puppet packages, services, and files II with nginx
Puppet templates
Puppet creating and managing user accounts with SSH access
Puppet Locking user accounts & deploying sudoers file
Puppet exec resource
Puppet classes and modules
Puppet Forge modules
Puppet Express
Puppet Express 2
Puppet 4 : Changes
Puppet --configprint
Puppet with Docker
Puppet 6.0.2 install on Ubuntu 18.04