I am writing this post as part of course Linuxin keskitetty hallinta held by Tero Karvinen. In this post I will write hello world module which use puppet templates and facter facts (ex. my hardware details).

See your computer details

When we run facter command, we will see our computer details. Read more: http://www.puppetcookbook.com/posts/list-facter-facts.html

$ facter -p

Create new module

Create new view for hardware_details module:

$ mkdir -p modules/hardware_details/templates/
$ nano modules/hardware_details/templates/details.erb

The code in details.erb:

Hardware model: <%= @hardwaremodel %>
Kernel version: <%= @kernelmajversion %>
Puppet version: <%= @puppetversion %>
Ruby version: <%= @rubyversion %>

Create new directory:

$ mkdir modules/hardware_details/manifests

Do next class in file modules/hardware_details/manifests/init.pp:

class hardware_details {
  file { '/tmp/hardwareDetail':
    content => template('hardware_details/details.erb'),
  }
}

Run puppet module:

$ puppet apply --modulepath modules/ -e 'class {"hardware_details":}'

Test module

Last we verify that module works right:

$ less /tmp/hardwareDetails

My result:
Hardware model: x86_64
Kernel version: 3.2
Puppet version: 2.7.11
Ruby version: 1.8.7