Ask Your Question
0

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: https://github.com/treydock/puppet-mo..., 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 ltstd001.healthplan.com","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 => { 'foo@example.com' => { '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
0

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.

https://github.com/treydock/puppet-mo...

edit flag offensive delete link more

Comments

Robust (ruby) templates would do a `unless ...nil?` check before trying to iterate over a `nil` value. For simple templates, *.epp templates https://docs.puppet.com/puppet/latest/lang_template_epp.html 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

Stats

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

Seen: 40 times

Last updated: Jan 11