From 063b83207c6fac682c4089844e1a5524d8006205 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 24 Jan 2013 22:39:31 -0200 Subject: Using hiera and parametrized classes --- manifests/init.pp | 30 +++++++++++++++++++----------- templates/ntp.conf.erb | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 3e7e4e3..a980efb 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,9 +1,11 @@ # This class ensures ntp is up'n running and synchronizing with ntp servers. -class timezone { +class timezone( + $zone = hiera('ntp::zone', '') +) { - case $ntp_timezone { - '': { fail("you need to define \$ntp_timezone for ntp module") } + case $zone { + '': { fail("you need to define ntp::zone for ntp module") } } # the needed packages @@ -11,15 +13,18 @@ class timezone { # adjust localtime file { "/etc/localtime": - ensure => "/usr/share/zoneinfo/${ntp_timezone}", + ensure => "/usr/share/zoneinfo/${zone}", require => Package["tzdata"], } } -class ntp inherits timezone { +class ntp( + $servers = hiera('ntp::servers', '') +) { + class { 'timezone': } - case $ntp_servers { - '': { fail("you need to define \$ntp_servers for ntp module") } + case $servers { + '': { fail("you need to define ntp::servers for ntp module") } } # the needed packages @@ -54,12 +59,15 @@ class ntp inherits timezone { } -class ntpdate inherits timezone { +class ntpdate( + $pool = hiera('ntp::pool', '') +) { + class { 'timezone': } # TODO: add logrotate rule to /var/log/ntpdate.log - case $ntp_pool { - '': { fail("you need to define \$ntp_pool for ntp module") } + case $pool { + '': { fail("you need to define ntp::pool for ntp module") } } # the needed packages @@ -69,7 +77,7 @@ class ntpdate inherits timezone { # adjust time using ntpdate cron { "ntpdate": - command => "/usr/sbin/ntpdate -t 5 ${ntp_pool} >> /var/log/ntpdate.log 2>&1", + command => "/usr/sbin/ntpdate -t 5 ${pool} >> /var/log/ntpdate.log 2>&1", user => root, hour => "*/1", minute => "10", diff --git a/templates/ntp.conf.erb b/templates/ntp.conf.erb index 988f310..ae86940 100644 --- a/templates/ntp.conf.erb +++ b/templates/ntp.conf.erb @@ -9,7 +9,7 @@ filegen peerstats file peerstats type day enable filegen clockstats file clockstats type day enable # ntp servers -<% ntp_servers.each do |server| -%>server <%= server => iburst<% end -%> +<% servers.each do |server| -%>server <%= server => iburst<% end -%> # configuracoes de restricao de acesso # access restrictions -- cgit v1.2.3