1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# Class: ntp
#
# This module manages the ntp service.
#
# Jeff McCune <jeff@puppetlabs.com>
# 2011-02-23
#
# Tested platforms:
# - Debian 6.0 Squeeze
# - CentOS 5.4
# - Amazon Linux 2011.09
# - FreeBSD 9.0
#
# Parameters:
#
# $servers = [ '0.debian.pool.ntp.org iburst',
# '1.debian.pool.ntp.org iburst',
# '2.debian.pool.ntp.org iburst',
# '3.debian.pool.ntp.org iburst', ]
#
# $restrict = true
# Whether to restrict ntp daemons from allowing others to use as a server.
#
# $autoupdate = false
# Whether to update the ntp package automatically or not.
#
# $enable = true
# Automatically start ntp deamon on boot.
#
# Actions:
#
# Installs, configures, and manages the ntp service.
#
# Requires:
#
# Sample Usage:
#
# class { "ntp":
# servers => [ 'time.apple.com' ],
# autoupdate => false,
# }
#
# [Remember: No empty lines between comments and class definition]
class ntp($servers='UNSET',
$ensure='running',
$enable=true,
$restrict=true,
$autoupdate=false
) {
if ! ($ensure in [ 'running', 'stopped' ]) {
fail('ensure parameter must be running or stopped')
}
if $autoupdate == true {
$package_ensure = latest
} elsif $autoupdate == false {
$package_ensure = present
} else {
fail('autoupdate parameter must be true or false')
}
case $::osfamily {
Debian: {
$supported = true
$pkg_name = [ 'ntp' ]
$svc_name = 'ntp'
$config = '/etc/ntp.conf'
$config_tpl = 'ntp.conf.debian.erb'
if ($servers == 'UNSET') {
$servers_real = [ '0.debian.pool.ntp.org iburst',
'1.debian.pool.ntp.org iburst',
'2.debian.pool.ntp.org iburst',
'3.debian.pool.ntp.org iburst', ]
} else {
$servers_real = $servers
}
}
RedHat: {
$supported = true
$pkg_name = [ 'ntp' ]
$svc_name = 'ntpd'
$config = '/etc/ntp.conf'
$config_tpl = 'ntp.conf.el.erb'
if ($servers == 'UNSET') {
$servers_real = [ '0.centos.pool.ntp.org',
'1.centos.pool.ntp.org',
'2.centos.pool.ntp.org', ]
} else {
$servers_real = $servers
}
}
SuSE: {
$supported = true
$pkg_name = [ 'ntp' ]
$svc_name = 'ntp'
$config = '/etc/ntp.conf'
$config_tpl = 'ntp.conf.suse.erb'
if ($servers == 'UNSET') {
$servers_real = [ '0.opensuse.pool.ntp.org',
'1.opensuse.pool.ntp.org',
'2.opensuse.pool.ntp.org',
'3.opensuse.pool.ntp.org', ]
} else {
$servers_real = $servers
}
}
FreeBSD: {
$supported = true
$pkg_name = ['net/ntp']
$svc_name = 'ntpd'
$config = '/etc/ntp.conf'
$config_tpl = 'ntp.conf.freebsd.erb'
if ($servers == 'UNSET') {
$servers_real = [ '0.freebsd.pool.ntp.org iburst maxpoll 9',
'1.freebsd.pool.ntp.org iburst maxpoll 9',
'2.freebsd.pool.ntp.org iburst maxpoll 9',
'3.freebsd.pool.ntp.org iburst maxpoll 9', ]
} else {
$servers_real = $servers
}
}
default: {
fail("The ${module_name} module is not supported on ${::osfamily} based systems")
}
}
package { 'ntp':
ensure => $package_ensure,
name => $pkg_name,
}
file { $config:
ensure => file,
owner => 0,
group => 0,
mode => '0644',
content => template("${module_name}/${config_tpl}"),
require => Package[$pkg_name],
}
service { 'ntp':
ensure => $ensure,
enable => $enable,
name => $svc_name,
hasstatus => true,
hasrestart => true,
subscribe => [ Package[$pkg_name], File[$config] ],
}
}
|