Let's build an example class that manages the NTP time service. The class will take an optional parameter specifying an NTP server to sync from.
First, create the directories for an
ntp
module:ubuntu@demo:~/puppet$ mkdir modules/ntp ubuntu@demo:~/puppet$ mkdir modules/ntp/manifests ubuntu@demo:~/puppet$ mkdir modules/ntp/templates
Create the file
modules/ntp/manifests/init.pp
with the following contents:# Manage NTP server class ntp($server='UNSET') { package { 'ntp': ensure => installed, } file { '/etc/ntp.conf': content => template('ntp/ntp.conf.erb'), notify => Service['ntp'], } service { 'ntp': ensure => running, enable => true, require => [ Package['ntp'], File['/etc/ntp.conf'] ], } }
Create the file
modules/ntp/templates/ntp.conf.erb
with the following contents:driftfile /var/lib/ntp/ntp.drift <% if server != 'UNSET' -%> server <%= server %> prefer <% end -%> server 0...