A node definition, also known as a node statement, is a block of Puppet code that is included only in matching nodes' catalogs. This allows you to assign specific configurations to specific nodes.
Put node definitions in the main manifest, which can be a single site.pp
file, or a directory containing many files.
If the main manifest contains at least one node definition, it must have one for every node. Compilation for a node fails if a node definition for it cannot be found. Either specify no node definitions, or use the default
node definition, as described below, to avoid this situation.
Puppet code that is outside any node definition is compiled for every node. That is, a given node gets both the code that is in its node definition and the code that is outside any node definition.
Node definitions are an optional feature of Puppet. You can use them instead of or in combination with an external node classifier (ENC). Alternatively, you can use conditional statements with facts to classify nodes. Unlike more general conditional structures, node definitions match nodes only by name. By default, the name of a node is its certname, which defaults to the node's fully qualified domain name.
-
Variables from an ENC are set at top scope and can be overridden by variables in a node definition.
-
Classes from an ENC are declared at node scope, so they are affected by any variables set in the node definition.
Syntax
-
The
node
keyword. -
The node definition name: a quoted string, a regular expression, or
default
. -
An opening curly brace.
-
Any mixture of class declarations, variables, resource declarations, collectors, conditional statements, chaining relationships, and functions.
-
A closing curly brace.
www1.example.com
receives the apache
and squid
classes, and only db1.example.com
receives the mysql
class:
A node definition name must be one of the following:
-
A quoted string containing only letters, numbers, underscores (
_
), hyphens (-
), and periods (.
). -
A regular expression.
-
The bare word
default
. If no other node definition matches a given node, thedefault
node definition will be used for that node.
www1
, www13
, and any other node whose name consists of www
and one or more digits:
The following example of a regex node definition name matches one.example.com
and two.example.com
, but no other nodes:
()
, and then referencing them in order as $1
, $2
and so on, as variables within the body of the node definition. For example:
Matching
-
If there is a node definition with the node's exact name, Puppet uses it.
-
If there is a regular expression node definition that matches the node's name, Puppet uses it. If more than one regex node matches, Puppet uses one of them, but we can't predict which. Make your node definition name regexes non-overlapping to avoid this problem.
-
If the node's name looks like a fully qualified domain name (it has multiple period-separated groups of letters, numbers, underscores, and dashes), Puppet chops off the final group and start again at step 1.
You can turn off this fuzzy name checking by changing the master'sstrict_hostname_checking
configuration setting totrue
. This causes Puppet to skip this looping step and use only the node’s full name before resorting todefault
. -
Puppet uses the
default
node.
www01.example.com
, with fuzzy checking, Puppet looks for a node definition with the following name, in this order:www01.example.com
A regex that matches
www01.example.com
www01.example
A regex that matches
www01.example
www01
A regex that matches
www01
default
default
node definition.