claranet / puppet-consul_template

A Puppet module to manage the config and jobs of Consul Template from Hashicorp
Apache License 2.0
30 stars 89 forks source link

Legacy 3.x function #121

Open AlessandroLorenzi opened 5 years ago

AlessandroLorenzi commented 5 years ago

Affected Puppet, Ruby, OS and module versions/distributions

Output log

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Illegal method definition of method 'sorted_generate' on line 8' in legacy function. See https://puppet.com/docs/puppet/latest/functions_refactor_legacy.html for more information (file: /etc/puppetlabs/code/environments/production/modules/consul_template/manifests/config.pp, line: 17, column: 19) on node web2
AlessandroLorenzi commented 5 years ago

Partial fix:

-module Puppet::Parser::Functions
-  newfunction(:consul_template_sorted_json, type: :rvalue, doc: <<-EOS
-This function takes unsorted hash and outputs JSON object making sure the keys are sorted.
-Optionally you can pass 2 additional parameters, pretty generate and indent length.
-
-*Examples:*
- [..snap..]
+Puppet::Functions.create_function(:consul_template_sorted_json) do
+  def consul_template_sorted_json(*args)
     unsorted_hash = args[0]      || {}
     pretty        = args[1]      || false
     indent_len    = args[2].to_i || 4
-
     return JSON.sorted_pretty_generate(unsorted_hash, indent_len) << "\n" if pretty
     JSON.sorted_generate(unsorted_hash)
   end

I have still this error:

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Illegal method definition of method 'sorted_generate' on line 8' in legacy function. See https://puppet.com/docs/puppet/latest/functions_refactor_legacy.html for more information (file: /etc/puppetlabs/code/environments/production/modules/consul_template/manifests/config.pp, line: 17, column: 19) on node web2
regner commented 5 years ago

Were you able to solve this?

regner commented 5 years ago

For anyone else running into this, someone else has already solved it in their fork (no PR from them yet): https://github.com/l-lotz/puppet-consul_template

ydixken commented 5 years ago

+1 for the PR

findmyname666 commented 2 years ago

Hello guys, do you plan to fix/merge this in the near future ?