Ask Your Question

Template incompatible with Puppet 4 but works with Puppet 3

asked 2017-01-11 04:59:06 -0500

bschonecker gravatar image

updated 2017-01-11 05:01:26 -0500

Using 'setroubleshoot' module located at:, I have been having trouble getting Puppet 4 to do a 'for each' loop in the template file against the hash (of hashes?).

When running on Puppet 4, the methods "keys.sort.each" fail for the hash @email_recipients in the template file:

    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 setroubleshoot/email_alert_recipients.erb:

Filepath: /etc/puppetlabs/code/environments/setroubleshoot/modules/setroubleshoot/templates/emailalertrecipients.erb Line: 1 * Detail: undefined methodkeys' for nil:NilClass * at /etc/puppetlabs/code/environments/setroubleshoot/modules/setroubleshoot/manifests/config.pp:22:18 on node","issuekind":"RUNTIMEERROR"} Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run

Using the puppet site.pp file:

class { 'setroubleshoot': 
  email_recipients => { '' => { 'filter_type' => 'after_first' } } 

Here's the template:

  <% @email_recipients.keys.sort.each do |recipient| -%>
  <% filter_type = @email_recipients[recipient]['filter_type'] || 'after_first' -%>
  <%= recipient %> filter_type=<%= filter_type %>
  <% end -%>

For the life of me I can't figure out why .keys.sort.each is failing. There's no issue with Puppet 3.x and I've not found any reason why the .keys, .each and .sort methods would have been deprecated (which wouldn't make any sense anyway).

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-01-11 05:43:59 -0500

bschonecker gravatar image

The problem was one of variable scope. The template thought that @email_recipients was nil so it always failed.

I've submitted a pull request to the owner of the module. I hope I used proper form 'fixing' the scope problem.

edit flag offensive delete link more


Robust (ruby) templates would do a `unless ...nil?` check before trying to iterate over a `nil` value. For simple templates, *.epp templates would be a nice choice to _restrict_ input values.

Kai Burghardt gravatar imageKai Burghardt ( 2017-01-11 11:16:23 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-01-11 04:59:06 -0500

Seen: 28 times

Last updated: Jan 11