Ask Your Question
0

How can I use the Ruby ternary operator in an EPP?

asked 2016-11-16 17:12:57 -0500

Rob Ogilvie gravatar image

If an incoming parameter matches a string, I want to output a different string. This seems an obvious ternary operator situation (if, then, else), but I'm receiving a syntax error.

<%= $gw_app == "ab" ? "cm" : $gw_app %>

results in:

Error: epp(): Invalid EPP: Syntax error at ':' at ....

when I run it through puppet epp render.

I don't have similar problems in irb:

irb(main):025:0> $gw_app="ab"
=> "ab"
irb(main):026:0> $gw_app == "ab" ? "cm" : $gw_app
=> "cm"
irb(main):027:0> $gw_app="pc"
=> "pc"
irb(main):028:0> $gw_app == "ab" ? "cm" : $gw_app
=> "pc"

How can I use the ternary operator in EPP, or do I need to use the long-form if/then/else?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-11-17 06:59:22 -0500

DarylW gravatar image

epp templates can only conatain valid puppet language constructs, and the epp templating syntax, not ruby.

https://docs.puppet.com/puppet/latest...

https://docs.puppet.com/puppet/latest...templateepp.html

edit flag offensive delete link more
0

answered 2016-11-17 07:05:37 -0500

with an erb file variables that where referenced as $ are now referenced with @ so would use:

 <%= @gw_app == "ab" ? "cm" : @gw_app %>
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: 2016-11-16 17:12:57 -0500

Seen: 114 times

Last updated: Nov 17 '16