Ask Your Question
0

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
  self.map{|i| "/some/path/to/prepend/*/#{i}" }.join(',')
 end
end

command_list1 = %w (command1.sh command2.sh command3.sh).to_sudo
command_list2 = %w (command4.sh command5.sh command6.sh).to_sudo
%>

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

Comments

Ffrank, I ended up working around the issue in a similar fashion, thanks. Submitted a JIRA to PuppetLabs : https://tickets.puppetlabs.com/browse/PUP-2318 , 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
0

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

Stats

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

Seen: 102 times

Last updated: Apr 21 '14