February 22, 2015

Puppet – Format of the ENC’s output


The yaml data outputted by ENC can only have 3 high level keys, classes, parameters, and environment. We’ll now take a look at each of these in turn.


You can find all my latest posts on medium.

The “classes” key

We have already come across this in the previous lesson. This basically is where you write all your node definition’s include statements in yaml form. However you can add class parameter values here as well, e.g.:

[root@puppetmaster yaml]# cat /tmp/node-definitions/

    username: james

[root@puppetmaster yaml]#

This is basically the equivalent of doing a resource-like class declaration, but in yaml form. By specifying your class parameters here, it means that the puppetmaster will no longer refer to hiera to lookup the value for the “username” class parameter.

However this approach isn’t good practice because Hiera is much better suited at keeping your class parameter data organized compared to using an ENC for this.

The “parameters” key

This basically let’s you attach variables to your puppet agent. These are facter, but in this case the puppet agent’s don’t derive the values, instead these values are defined by the ENC.

One possible use for this, is that you can use this way to attach metadata to your puppet agent (although external facts might be a better way of doing this). For example your puppet agent may be provisioned for use in IT project called “Genesis” in order to build an IT system called “Skynet”. In that case you can attach these metadata to your puppet agent like this:

[root@puppetmaster yaml]# cat /tmp/node-definitions/

  - user_account:

  - project_name: Genesis
  - system_name:  Skynet    
[root@puppetmaster yaml]#

These paremeters are then available to the puppetmaster in the same style as any order facter data. Hence you can use them as part of things like puppet if-else statements, and generating contents for files.

for example if the user_account module’s init.pp contains:

[root@puppetmaster yaml]# cat /etc/puppet/modules/user_account/manifests/init.pp
class user_account ($username = "tempuser"){

  user { "$username":
    ensure => present,
    shell  => '/bin/bash',

  file {"/tmp/testfile.txt":
    ensure => file,
    content => "The project name is: $project_name and the IT system name is $system_name. \n",

[root@puppetmaster yaml]#

In that case, if we do a puppet run, we get:

[root@puppetagent1 tmp]# cat /tmp/testfile.txt
cat: /tmp/testfile.txt: No such file or directory
[root@puppetagent1 tmp]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for
Info: Applying configuration version '1424636188'
Notice: /Stage[main]/User_account/File[/tmp/testfile.txt]/ensure: defined content as '{md5}4a0f48e055fa3de603280a5e268d4c26'
Notice: Finished catalog run in 0.04 seconds
[root@puppetagent1 tmp]# cat /tmp/testfile.txt
The project name is: Genesis and the IT system name is Skynet.
[root@puppetagent1 tmp]#

The “environment” key

This is linked related to the Puppet agent’s environment config setting, under the [main] section.

This setting is specifically used for setting up a powerful feature called directory environments.

Normally you set this in the puppet agent’s puppet.conf file, e.g.:

[root@puppetagent1 tmp]# cat /etc/puppet/puppet.conf
    # The Puppet log directory.
    # The default value is '$vardir/log'.
    logdir = /var/log/puppet

    # Where Puppet PID files are kept.
    # The default value is '$vardir/run'.
    rundir = /var/run/puppet

    # Where SSL certificates are kept.
    # The default value is '$confdir/ssl'.
    ssldir = $vardir/ssl

    environment=test                              # here

    # The file in which puppetd stores a list of the classes
    # associated with the retrieved configuratiion.  Can be loaded in
    # the separate ``puppet`` executable using the ``--loadclasses``
    # option.
    # The default value is '$confdir/classes.txt'.
    classfile = $vardir/classes.txt

    # Where puppetd caches the local configuration.  An
    # extension indicating the cache format is added automatically.
    # The default value is '$confdir/localconfig'.
    localconfig = $vardir/localconfig
[root@puppetagent1 tmp]#

So that:

[root@puppetagent1 /]# puppet config print environment
[root@puppetagent1 /]#

However individually logging into all the agents to do this can be tedious. Hence, it’s easier to set this centrally.