Ask Your Question

ERB template fails after upgrade to Puppet 4 [closed]

asked 2016-10-26 12:53:18 -0500

evil_del gravatar image

Hi, we're upgrading from Puppet 3 to Puppet 4 and hit some issues with custom facts no longer working. Custom fact name: logservers.rb, it returns a string of IPs: ', 5,6,7,8'. We then turn the string into an array: $logservers = split($::logservers, ', ')

We use that variable in a template: rsyslog/central_logging.conf.erb that creates an rsyslog.d config file using this ERB code:

<% @logservers.each_with_index do |server, index| -%>
<% if index == 0 -%>
*.* <%= server %>
<% else -%>
& <%= server %>
<% end -%>
<% end -%>

This fails to parse with the error below. How can I recreate this config file in Puppet 4?

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: {"message":"Server Error: Evaluation Error: Error while evaluating a Function Call, Failed to parse template rsyslog/central_logging.conf.erb:\n  Filepath: /etc/puppetlabs/code/modules/rsyslog/templates/central_logging.conf.erb\n  Line: 4\n  Detail: undefined method `each_with_index' for \",\":String\n at /etc/puppetlabs/code/modules/rsyslog/manifests/config.pp:7
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by evil_del
close date 2016-11-14 14:30:57.185099


This is a (j)ruby error, not a Puppet error. There are some google results for jruby, error, and each_with_index. Maybe you should look into that?

pascal gravatar imagepascal ( 2016-10-27 05:20:13 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-10-27 11:21:48 -0500

smarlow gravatar image

updated 2016-10-27 11:36:16 -0500

The Ruby stacktrace is complaining that the string class doesn't have the each_with_index method. The issue then is that the template is seeing @logservers as a string, rather than an array. This is complicated by the fact that you are shadowing the top scope fact $::logservers with a local variable $logservers.

I think that there a couple of ways you could resolve this:

1) Avoid shadowing the fact and rename your local variable from $logservers to $logservers_real or something similar, and change the ERB template to match that.


  $logservers_real = split($::logservers, ',')

  <% @logservers_real.each_with_index do |server, index| -%>

2) If your logservers fact is always transformed into an array of strings, you could have your fact return that array by itself, and then you could just use the fact directly. In effect you'd just have the fact perform the split instead of the manifest. See this link for more information.


  Facter.add(:logservers) do
    setcode do
      logservers = ...
      # Split into an array and return it as the fact value
edit flag offensive delete link more


Thanks. These steps fixed it for me. The custom fact wasn't returning what I expected it to.

evil_del gravatar imageevil_del ( 2016-11-06 16:16:15 -0500 )edit

Question Tools

1 follower


Asked: 2016-10-26 12:53:18 -0500

Seen: 101 times

Last updated: Oct 27 '16