▶ Puppet topics part 1: Tags – Undef

Puppet is a powerful Configuration Management Tool used in a lot of corporate environements.

Here are some tips and tricks for testing and writing modules and manifest:

1. Tags

Tags are useful: especially when testing manifests/classes the class name can be tagged.

Collecting Resources

Tags can be used as an attribute in the search expression of a resource collector. This is mostly useful for realizing virtual and exported resources.
Restricting Catalog Runs

Puppet agent and Puppet apply can use the tags setting to only apply a subset of the node’s catalog. This is useful when refactoring modules, and allows you to only apply a single class on a test node.

The tags setting can be set in puppet.conf (to permanently restrict the catalog) or on the command line (to temporarily restrict it):

$ sudo puppet agent –test –tags apache,us_mirror1

The value of the tags setting should be a comma-separated list of tags (with no spaces between tags).

 2. Use undef

Sometimes it is useful to check if a variable (not) exists, for that you can use undef:


Puppet’s special undef value is roughly equivalent to nil in Ruby; variables which have never been declared have a value of undef. Literal undef values must be the bare word undef.

The undef value is usually useful for testing whether a variable has been set. It can also be used as the value of a resource attribute, which can let you un-set any value inherited from a resource default and cause the attribute to be unmanaged.

When used as a boolean, undef is false.

Below is a check to check if a variable is declared (same as NOT undefined)

if $uniquevar != undef { fail(“Conflicting facts in /etc/facter/facts.d: uniquevar also defined: $uniquevar”) }