Welcome fellow earthling!

You have landed on my notebook, where I keep my notes.

Puppet: Using Templates and Facter facts

I did some experimenting on using templates and Facter on Puppet with Package-File-Service manifest structure.

Rewriting /etc/motd-file using a Puppet module template

For the template testing I decided to use it on motd-file, which is used to display a message when you log on a linux-machine from command line.

First I created the directory structure for the new module “motdtest” with the following command:

mkdir -p motdtest/manifests

Then I created a new manifest file:

nano motdtest/manifests/init.pp

I wrote the following to the init.pp-file:

class motdtest {
    file { '/etc/motd':<
        content => template("motdtest/motdtest.erb"),

Then I created the templates directory to the  module root:

mkdir motdtest/templates
nano motdtest/templates/motdtest.erb

And wrote a message in the file:


After saving the template file I made a test run on the module to see if it would work:

sudo puppet apply --modulepath modules/ -e 'class {"motdtest":}'

(Sudo is needed because we are making changes to a system config file with this module.)


After I run the command above, it says that it has updated the content on /etc/motd-file. Let’s see if my message is in the file:


Adding Facter variables

I edited the template file to look like this:


You can find more facts available with command “facter” and even more with “facter -p”. After saving the changes to the template, I applied the module again:

sudo puppet apply --modulepath modules/ -e 'class {"motdtest":}'


And this is the result of the modifications:



Next Post Previous Post