Ask Your Question

Using Ruby open classes in Puppet Templates

asked 2014-04-21 09:48:01 -0500

mapa3m gravatar image

I have a Ruby template (.erb) that has the following code, used to build SUDO files out of lists of commands:

class Array
 def to_sudo{|i| "/some/path/to/prepend/*/#{i}" }.join(',')

command_list1 = %w (
command_list2 = %w (

Cmnd_Alias CMD1 = <%= command_list1 %>
Cmnd_Alias CMD2 = <%= command_list2 %>

... and so on, there are about a dozen different lists/aliases/etc

Works just fine when compiled directly with "erb filename.erb", output is as expected. However, when I try to run it via Puppet, I get the following error, both via RSpec-Puppet and "puppet apply":

Detail: undefined method `to_sudo' for #<Array:0x7fe8e50fd680>
edit retag flag offensive close merge delete


Ffrank, I ended up working around the issue in a similar fashion, thanks. Submitted a JIRA to PuppetLabs : , since it might actually be a bug

mapa3m gravatar imagemapa3m ( 2014-04-22 08:29:17 -0500 )edit

Awesome, thanks for ticketing. I made that my answer then ;-)

ffrank gravatar imageffrank ( 2014-04-22 15:23:56 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-04-22 07:39:13 -0500

ffrank gravatar image

Interesting effect, might be considered a bug. Either way, I'd recommend to perform your array munging in a parser function and hand the compiled list to your template instead.

edit flag offensive delete link more

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: 2014-04-21 09:48:01 -0500

Seen: 102 times

Last updated: Apr 21 '14