I was going through the Puppet Learning doc.
Got to the template section and the ERB file, which is using the 'each' method to print the $real_servers.
The puppet run fails with pointing to the 'each' method.
Is this a bug? does anyone have any pointers?
Using:
centos 6.6
puppet 3.8.1
ruby 1.8.7
Thanks.
# cat /etc/puppet/modules/ntp/manifests/init.p
class ntp {
# Choose platform, package name, and config file name
case $operatingsystem {
centos, redhat: {
$service_name = 'ntpd'
$conf_file = 'ntp.conf'
$default_servers = [ "
0.centos.pool.ntp.org",
"
1.centos.pool.ntp.org",
"
2.centos.pool.ntp.org", ]
}
debian, ubuntu: {
$service_name = 'ntp'
$conf_file = 'ntp.conf.debian'
$default_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", ]
}
default: { fail("Unrecognized operating system for webserver") }
}
$servers_real = $default_servers
# Install the package
package { 'ntp':
ensure => installed,
}
# Get the config file
file { 'ntp.conf':
path => '/etc/ntp.conf',
ensure => file,
require => Package['ntp'],
content => template("ntp/${conf_file}.erb"),
}
# Manage the service
service { 'ntp':
name => $service_name,
ensure => running,
enable => true,
subscribe => File['ntp.conf'],
}
} #class
# cat /etc/puppet/modules/ntp/templates/ntp.conf.erb
<% @servers_real.each do |this_server| -%>
server <%= this_server %>
<% end -%>
# puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template ntp/ntp.conf.erb:
Filepath: /etc/puppet/modules/ntp/templates/ntp.conf.erb
Line: 2
Detail: undefined method `each' for nil:NilClass
at /etc/puppet/modules/ntp/manifests/init.pp:26 on node
puppetmaster.example.comWarning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run